Skip to content

Add Precompiles #10

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/generators/html5/assets/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def generate_stylesheet_partials
end
end

# TODO
# def add_precompiles
# end
def add_precompiles
gsub_file "config/environments/production.rb", "# config.assets.precompile += %w( search.js )", "config.assets.precompile += %w( polyfills.js )"

Choose a reason for hiding this comment

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

Wouldn't it be better to keep the comment in the file for future reference and add the config line after it?

Copy link
Author

Choose a reason for hiding this comment

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

The line above this has a comment explaining what it does: "Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)." And, since the example I removed is so similar to the new line, I don't think there's much value leaving it in. I assumed it was standard to remove the example in cases like this, but I can leave it in if it's not.

Choose a reason for hiding this comment

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

I understand why you choose to replace the comment, but now after looking closely to this way of adding precompiles I see 2 problems with it:

  1. What if another generator wants to add an asset too to the precompiles? It might use the same kind of code and expect the comment to exist.
  2. What if the user has deleted this comment and added a custem asset to the precomiles?

I'm not so familiar with rails generators so I can't suggest a better way yet, but I hope you'll see why I think this implementation is a bit dangerous.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, that's a good point. I think the correct way to do might be something like:

application(nil, :env => "production") do "#{application_name}::Application.config.assets.precompile += %w( polyfills.js )" end

(from http://guides.rubyonrails.org/generators.html#application), but I'm not sure.

end

protected

Expand All @@ -60,4 +60,4 @@ def stylesheet_partials
end
end
end
end
end