Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generators for asset files #326

Merged
merged 1 commit into from
Dec 15, 2015
Merged

Add generators for asset files #326

merged 1 commit into from
Dec 15, 2015

Conversation

c-lliope
Copy link
Contributor

Closes #187

Problem:

Many people want to customize the stylesheets and javascripts
that get applied to Administrate dashboards.

To do that, they must copy over the default assets
from Adminsitrate's source into their own host application,
and edit those files to add custom behavior or styles.

This approach is error-prone and not approachable.

Solution:

Add a generator for copying over default styles and javascripts
into the user's host application.

Usage:

 # Copy image assets into `app/assets/images/administrate`
rails generate administrate:assets:images

 # Copy javascript assets into `app/assets/javascripts/administrate`
rails generate administrate:assets:javascripts

 # Copy stylesheet assets into `app/assets/stylesheets/administrate`
rails generate administrate:assets:stylesheets

 # Runs all of the above generators
rails generate administrate:assets

ToDo:

  • Actually run these generators and edit the files to verify they work.

describe "administrate:assets" do
it "runs all sub-generators" do
allow(Rails::Generators).to receive(:invoke)
resource = "users"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - resource.

@c-lliope
Copy link
Contributor Author

One drawback of this implementation is that the administrate:assets generator doesn't work for Rails apps where the app is not at the root of the repository.

When I run rails generate administrate:assets, I expect the files to be generated into spec/example_app/app/assets/. However, they are instead generated into app/assets/.

1__tmux

I tried specifying Rails.root (see b1f557f and 622aa1a), but that isn't supported by Ammeter, which is what we're using to test the generators.

I expect this to be an incredibly uncommon use case, so I'm OK pushing this forward. Thoughts?

module Administrate
module Generators
class AssetsGenerator < Administrate::ViewGenerator
def copy_templates
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to copy_assets

Problem:

Many people want to customize the stylesheets and javascripts
that get applied to Administrate dashboards.

To do that, they must copy over the default assets
from Adminsitrate's source into their own host application,
and edit those files to add custom behavior or styles.

This approach is error-prone and not approachable.

Solution:

Add a generator for copying over default styles and javascripts
into the user's host application.

Usage:

```
 # Copy image assets into `app/assets/images/administrate`
rails generate administrate:assets:images

 # Copy javascript assets into `app/assets/javascripts/administrate`
rails generate administrate:assets:javascripts

 # Copy stylesheet assets into `app/assets/stylesheets/administrate`
rails generate administrate:assets:stylesheets

 # Runs all of the above generators
rails generate administrate:assets
```
@c-lliope c-lliope closed this Dec 15, 2015
@c-lliope c-lliope deleted the gw-generate-assets branch December 15, 2015 02:02
@c-lliope c-lliope merged commit c132777 into master Dec 15, 2015
@rikkipitt
Copy link
Contributor

Cheers @Graysonwright, I'll check this out soon. Does it help the production of custom plugins like we were talking about before too?

@c-lliope
Copy link
Contributor Author

c-lliope commented Mar 7, 2016

@rikkipitt sorry for the late response.

This is a step in that direction. We're also working on #476, which will really help out with custom plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants