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 Precompiles #10

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
3 participants
@sidnair

sidnair commented Jan 6, 2012

I think this is the only change required for precompilation to work.

Edit: I just saw issue 9. I'll leave this issue open in case you decide against using an initializer. Sorry for the duplication.

# 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 )"

This comment has been minimized.

@Maher4Ever

Maher4Ever Jan 7, 2012

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

@Maher4Ever

Maher4Ever Jan 7, 2012

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

This comment has been minimized.

@sidnair

sidnair Jan 7, 2012

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.

@sidnair

sidnair Jan 7, 2012

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.

This comment has been minimized.

@Maher4Ever

Maher4Ever Jan 7, 2012

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.

@Maher4Ever

Maher4Ever Jan 7, 2012

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.

This comment has been minimized.

@sidnair

sidnair Jan 7, 2012

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.

@sidnair

sidnair Jan 7, 2012

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.

@sporkd

This comment has been minimized.

Show comment
Hide comment
@sporkd

sporkd Jan 10, 2012

Owner

Thanks for the work on this. I was toying with the idea of just adding the configuration inside the gem, similar to this: https://github.com/indirect/haml-rails/blob/master/lib/haml-rails.rb#L7-11

However, I don't want to force the use of polyfills.js just by virtue of loading the gem. I think perhaps the best compromize is to generate a new initializer in config/initializers. That way it can be deleted. I also don't think you want to force env production since you have full control of what environment you run the precompile rake task. So presumably it only gets run on deploy to production (or staging) anyway. But I like to run it in development sometimes just to see if it's working.

Owner

sporkd commented Jan 10, 2012

Thanks for the work on this. I was toying with the idea of just adding the configuration inside the gem, similar to this: https://github.com/indirect/haml-rails/blob/master/lib/haml-rails.rb#L7-11

However, I don't want to force the use of polyfills.js just by virtue of loading the gem. I think perhaps the best compromize is to generate a new initializer in config/initializers. That way it can be deleted. I also don't think you want to force env production since you have full control of what environment you run the precompile rake task. So presumably it only gets run on deploy to production (or staging) anyway. But I like to run it in development sometimes just to see if it's working.

@sporkd

This comment has been minimized.

Show comment
Hide comment
@sporkd

sporkd Jan 12, 2012

Owner

For some reason I thought config.assets.precompile was in application.rb, but its in production. So using @sidnair09s example might be a good option. Sorry. I'll try and get this implemented or merged in the next day or so.

Owner

sporkd commented Jan 12, 2012

For some reason I thought config.assets.precompile was in application.rb, but its in production. So using @sidnair09s example might be a good option. Sorry. I'll try and get this implemented or merged in the next day or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment