Class: PictureTag::Instructions::TagParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_picture_tag/instructions/tag_parser.rb

Overview

This tag takes the arguments handed to the liquid tag, and extracts the preset name (if present), source image name(s), and associated media queries (if present). The leftovers (html attributes) are handed off to its respective class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_params) ⇒ TagParser

Returns a new instance of TagParser.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 9

def initialize(raw_params)
  build_params PictureTag::Utils.liquid_lookup(raw_params)

  @preset_name = grab_preset_name

  # The first param specified will be our base image, so it has no
  # associated media query.
  @media_presets = []
  @source_names = [] << strip_quotes(@params.shift)

  # Detect and store arguments of the format 'media_query: img.jpg' as
  # keys and values.
  add_media_source while @params.first =~ /[\w\-]+:$/
end

Instance Attribute Details

#media_presetsObject (readonly)

Returns the value of attribute media_presets.



8
9
10
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 8

def media_presets
  @media_presets
end

#preset_nameObject (readonly)

Returns the value of attribute preset_name.



8
9
10
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 8

def preset_name
  @preset_name
end

#source_namesObject (readonly)

Returns the value of attribute source_names.



8
9
10
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 8

def source_names
  @source_names
end

Instance Method Details

#leftoversObject



24
25
26
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 24

def leftovers
  @params
end