Class: LazyImages::Rails::Placeholder
- Inherits:
-
Object
- Object
- LazyImages::Rails::Placeholder
- Includes:
- ActionView::Helpers::AssetTagHelper
- Defined in:
- lib/lazy_images/rails/placeholder.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#svg ⇒ Object
readonly
Returns the value of attribute svg.
Instance Method Summary collapse
-
#initialize(svg, options) ⇒ Placeholder
constructor
A new instance of Placeholder.
- #to_s ⇒ Object
Constructor Details
#initialize(svg, options) ⇒ Placeholder
Returns a new instance of Placeholder.
11 12 13 14 |
# File 'lib/lazy_images/rails/placeholder.rb', line 11 def initialize(svg, ) @svg = svg @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/lazy_images/rails/placeholder.rb', line 9 def @options end |
#svg ⇒ Object (readonly)
Returns the value of attribute svg.
8 9 10 |
# File 'lib/lazy_images/rails/placeholder.rb', line 8 def svg @svg end |
Instance Method Details
#to_s ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lazy_images/rails/placeholder.rb', line 16 def to_s if [:size] # N. B. extract_dimensions is a private method from # actionview/lib/action_view/helpers/asset_tag_helper.rb # beware of breakage [:width], [:height] = extract_dimensions(.delete(:size)) fragment = Nokogiri::XML::DocumentFragment.parse(svg) fragment.first_element_child['width'] = [:width] fragment.first_element_child['height'] = [:height] fragment.to_s else svg end end |