Module: JavascriptFeatures::Helper
- Included in:
- TestCase
- Defined in:
- lib/javascript_features/helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #include_javascript_features(package = 'main') ⇒ Object
- #javascript_feature_classes ⇒ Object
- #use_javascript_for(*features) ⇒ Object
- #use_javascript_for?(feature) ⇒ Boolean
Class Method Details
.included(controller) ⇒ Object
4 5 6 |
# File 'lib/javascript_features/helper.rb', line 4 def self.included(controller) controller.helper_method :use_javascript_for, :use_javascript_for?, :javascript_feature_classes, :include_javascript_features if controller.respond_to? :helper_method end |
Instance Method Details
#include_javascript_features(package = 'main') ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/javascript_features/helper.rb', line 22 def include_javascript_features(package = 'main') query = Compiler.package_modified_time(package).to_i tag = %Q{<script type="text/javascript" src="/javascripts/packaged/#{package}.js?#{query}"></script>} if tag.respond_to?(:html_safe) tag.html_safe else tag end end |
#javascript_feature_classes ⇒ Object
18 19 20 |
# File 'lib/javascript_features/helper.rb', line 18 def javascript_feature_classes (@javascript_features || []).uniq.map{ |feature| "with-js-#{feature}" }.join(" ") end |
#use_javascript_for(*features) ⇒ Object
8 9 10 11 12 |
# File 'lib/javascript_features/helper.rb', line 8 def use_javascript_for(*features) @javascript_features ||= [] @javascript_features += features.map{|f| f.to_s.downcase } response.headers['X-JavascriptFeatures-Init'] = @javascript_features.uniq.join(' ') if request && request.xhr? end |
#use_javascript_for?(feature) ⇒ Boolean
14 15 16 |
# File 'lib/javascript_features/helper.rb', line 14 def use_javascript_for?(feature) @javascript_features.include?(feature.to_s.downcase) end |