Module: Preprocessor::Image

Included in:
BasicPreprocessor
Defined in:
lib/preprocessor/image.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/preprocessor/image.rb', line 4

def options
  @options
end

Instance Method Details

#image(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/preprocessor/image.rb', line 9

def image(options)
  attrs = {
    :src => absolutize(options[:src], ::Preprocessor::Image.options[:default_path]),
    :alt => options[:alt] || "",
    :title => options[:title] == "alt" ? options[:alt] : options[:title]
  }

  caption_text = case options[:caption]
  when "alt"
    attrs[:alt]
  when "title"
    attrs[:title]
  else
    options[:caption]
  end

  caption = %{<span class="caption">#{caption_text}</span>}
  attr_str = attrs.map { |k, v| %{#{k}="#{v}"} }.join(' ')

  %{<p class="image"><img #{attr_str} />#{caption}</p>}
end