Module: Spar::Helpers
- Included in:
- DirectiveProcessor, Sprockets::Context
- Defined in:
- lib/spar/helpers.rb
Defined Under Namespace
Classes: Paths
Class Method Summary collapse
Instance Method Summary collapse
-
#audio_path(source, options = {}) ⇒ Object
(also: #path_to_audio)
Helper methods for the spar context.
- #font_path(source, options = {}) ⇒ Object (also: #path_to_font)
- #image_path(source, options = {}) ⇒ Object (also: #path_to_image)
- #javascript_include_tag(*sources) ⇒ Object
- #javascript_path(source, options = {}) ⇒ Object (also: #path_to_javascript)
- #javascript_tag(src) ⇒ Object
- #path_to(asset_name, options = {}) ⇒ Object
- #stylesheet_link_tag(*sources) ⇒ Object
- #stylesheet_path(source, options = {}) ⇒ Object (also: #path_to_stylesheet)
- #stylesheet_tag(src) ⇒ Object
- #video_path(source, options = {}) ⇒ Object (also: #path_to_video)
Class Method Details
.append_features(context) ⇒ Object
:nodoc:
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spar/helpers.rb', line 12 def append_features(context) # :nodoc: context.class_eval do context_methods = context.instance_methods(false) Helpers.public_instance_methods.each do |method| remove_method(method) if context_methods.include?(method) end end super(context) end |
Instance Method Details
#audio_path(source, options = {}) ⇒ Object Also known as: path_to_audio
Helper methods for the spar context
64 65 66 |
# File 'lib/spar/helpers.rb', line 64 def audio_path(source, = {}) path_to source, { :dir => 'audios' }.merge() end |
#font_path(source, options = {}) ⇒ Object Also known as: path_to_font
69 70 71 |
# File 'lib/spar/helpers.rb', line 69 def font_path(source, = {}) path_to source, { :dir => 'fonts' }.merge() end |
#image_path(source, options = {}) ⇒ Object Also known as: path_to_image
74 75 76 |
# File 'lib/spar/helpers.rb', line 74 def image_path(source, = {}) path_to source, { :dir => 'images' }.merge() end |
#javascript_include_tag(*sources) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spar/helpers.rb', line 31 def javascript_include_tag(*sources) sources.collect do |source| if Spar.settings['debug'] && asset = Helpers.paths.asset_for(source, 'js') asset.to_a.map { |dep| javascript_tag(path_to(dep, :ext => 'js', :body => true)) } else javascript_tag(path_to(source, :ext => 'js', :body => false)) end end.join("\n") end |
#javascript_path(source, options = {}) ⇒ Object Also known as: path_to_javascript
79 80 81 |
# File 'lib/spar/helpers.rb', line 79 def javascript_path(source, = {}) path_to source, { :dir => 'javascripts', :ext => 'js' }.merge() end |
#javascript_tag(src) ⇒ Object
43 44 45 |
# File 'lib/spar/helpers.rb', line 43 def javascript_tag(src) "<script src='#{src}' charset='utf-8'></script>" end |
#path_to(asset_name, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/spar/helpers.rb', line 25 def path_to(asset_name, ={}) asset_name = asset_name.logical_path if asset_name.respond_to?(:logical_path) path = Helpers.paths.compute_public_path(asset_name, .merge(:body => true)) [:body] ? "#{path}?body=1" : path end |
#stylesheet_link_tag(*sources) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spar/helpers.rb', line 47 def stylesheet_link_tag(*sources) sources.collect do |source| if Spar.settings['debug'] && asset = Helpers.paths.asset_for(source, 'css') asset.to_a.map { |dep| stylesheet_tag(path_to(dep, :ext => 'css', :body => true, :protocol => :request)) } else stylesheet_tag(path_to(source, :ext => 'css', :body => false, :protocol => :request)) end end.join("\n") end |
#stylesheet_path(source, options = {}) ⇒ Object Also known as: path_to_stylesheet
84 85 86 |
# File 'lib/spar/helpers.rb', line 84 def stylesheet_path(source, = {}) path_to source, { :dir => 'stylesheets', :ext => 'css' }.merge() end |
#stylesheet_tag(src) ⇒ Object
59 60 61 |
# File 'lib/spar/helpers.rb', line 59 def stylesheet_tag(src) "<link href='#{src}' rel='stylesheet'>" end |
#video_path(source, options = {}) ⇒ Object Also known as: path_to_video
89 90 91 |
# File 'lib/spar/helpers.rb', line 89 def video_path(source, = {}) path_to source, { :dir => 'videos' }.merge() end |