Class: AssetLibrary::Helpers::Priv
- Inherits:
-
Object
- Object
- AssetLibrary::Helpers::Priv
- Defined in:
- lib/asset_library/helpers.rb
Instance Attribute Summary collapse
-
#helper ⇒ Object
Don’t pollute helper’s class’s namespace with all our methods; put them here instead.
Instance Method Summary collapse
- #absolute_url(relative_url) ⇒ Object
- #attributes_from_hash(options = {}) ⇒ Object
- #content_tag(name, content, options = {}) ⇒ Object
- #import_style_tag(assets, html_options = {}) ⇒ Object
- #import_styles_tag(assets, html_options = {}) ⇒ Object
-
#initialize(helper) ⇒ Priv
constructor
A new instance of Priv.
- #script_tag(asset) ⇒ Object
- #style_tag(asset, html_options = {}) ⇒ Object
- #url(asset) ⇒ Object
Constructor Details
#initialize(helper) ⇒ Priv
Returns a new instance of Priv.
41 42 43 |
# File 'lib/asset_library/helpers.rb', line 41 def initialize(helper) @helper = helper end |
Instance Attribute Details
#helper ⇒ Object
Don’t pollute helper’s class’s namespace with all our methods; put them here instead
39 40 41 |
# File 'lib/asset_library/helpers.rb', line 39 def helper @helper end |
Instance Method Details
#absolute_url(relative_url) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/asset_library/helpers.rb', line 49 def absolute_url(relative_url) host = helper.__send__(:compute_asset_host, relative_url) if helper.respond_to?(:compute_asset_host, true) host = nil if host == '' # Rails sets '' by default if host && !(host =~ %r{^[-a-z]+://}) controller = helper.instance_variable_get(:@controller) request = controller && controller.respond_to?(:request) && controller.request host = request && "#{request.protocol}#{host}" end if host "#{host}#{relative_url}" else relative_url end end |
#attributes_from_hash(options = {}) ⇒ Object
92 93 94 |
# File 'lib/asset_library/helpers.rb', line 92 def attributes_from_hash( = {}) .to_a.collect{|k, v| "#{k}=\"#{v}\""}.join(" ") end |
#content_tag(name, content, options = {}) ⇒ Object
88 89 90 |
# File 'lib/asset_library/helpers.rb', line 88 def content_tag(name, content, = {}) "<#{name} #{attributes_from_hash()}>#{content}</#{name}>" end |
#import_style_tag(assets, html_options = {}) ⇒ Object
83 84 85 86 |
# File 'lib/asset_library/helpers.rb', line 83 def import_style_tag(assets, = {}) imports = assets.collect{ |a| "@import \"#{url(a)}\";" } content_tag(:style, "\n#{imports.join("\n")}\n", .merge(:type => "text/css")) end |
#import_styles_tag(assets, html_options = {}) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/asset_library/helpers.rb', line 75 def import_styles_tag(assets, = {}) a = [] assets.each_slice(30) do |subset| a << import_style_tag(subset, ) end a.join("\n") end |
#script_tag(asset) ⇒ Object
67 68 69 |
# File 'lib/asset_library/helpers.rb', line 67 def script_tag(asset) content_tag(:script, "", {:type => "text/javascript", :src => url(asset)}) end |
#style_tag(asset, html_options = {}) ⇒ Object
71 72 73 |
# File 'lib/asset_library/helpers.rb', line 71 def style_tag(asset, = {}) "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{url(asset)}\" #{attributes_from_hash()}/>" end |
#url(asset) ⇒ Object
45 46 47 |
# File 'lib/asset_library/helpers.rb', line 45 def url(asset) absolute_url(asset.relative_url) end |