Class: ComfortableMexicanSofa::Content::Tag::Asset
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::Asset
- Defined in:
- lib/comfortable_mexican_sofa/content/tags/asset.rb
Overview
This tag allows for linking of js and css content defined on the layout. Looks something like this:
{{cms:asset layout_identifier, type: css, as: tag}}
‘type` - css | js - what we’re outputting here ‘as` - url (default) | tag - output url or wrap it in the appropriate tag
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from ComfortableMexicanSofa::Content::Tag
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(context, params_string) ⇒ Asset
constructor
A new instance of Asset.
- #layout ⇒ Object
Methods inherited from ComfortableMexicanSofa::Content::Tag
#allow_erb, #nodes, #parse_params_string, #render
Constructor Details
#initialize(context, params_string) ⇒ Asset
Returns a new instance of Asset.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/comfortable_mexican_sofa/content/tags/asset.rb', line 12 def initialize(context, params_string) super = params. @identifier = params[0] @type = ["type"] @as = ["as"] || "url" unless @identifier.present? raise Error, "Missing layout identifier for asset tag" end end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
10 11 12 |
# File 'lib/comfortable_mexican_sofa/content/tags/asset.rb', line 10 def as @as end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
10 11 12 |
# File 'lib/comfortable_mexican_sofa/content/tags/asset.rb', line 10 def identifier @identifier end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/comfortable_mexican_sofa/content/tags/asset.rb', line 10 def type @type end |
Instance Method Details
#content ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/comfortable_mexican_sofa/content/tags/asset.rb', line 29 def content return "" unless layout base = ComfortableMexicanSofa.config.public_cms_path || '' unless base.ends_with?("/") base = base + "/" end case @type when "css" out = "#{base}cms-css/#{context.site.id}/#{@identifier}/#{layout.cache_buster}.css" if @as == 'tag' out = "<link href='#{out}' media='screen' rel='stylesheet' type='text/css' />" end out when "js" out = "#{base}cms-js/#{context.site.id}/#{@identifier}/#{layout.cache_buster}.js" if @as == "tag" out = "<script src='#{out}' type='text/javascript'></script>" end out end end |
#layout ⇒ Object
25 26 27 |
# File 'lib/comfortable_mexican_sofa/content/tags/asset.rb', line 25 def layout @layout ||= context.site.layouts.find_by(identifier: @identifier) end |