Class: PictureTag::Instructions::TagParser

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

Overview

Tag Parsing Responsibilities:

{% picture mypreset a.jpg 3:2 mobile: b.jpg --alt "Alt" --link "/" %}

| Jekyll | TagParser | HTMLAttributes |

This class takes the arguments handed to the liquid tag (given as a simple string), hands them to ArgSplitter (which breaks them up into an array of words), extracts the preset name (if present), source image name(s), associated media queries (if present), and image-related arguments such as crop and gravity. HTML attributes are handed off to its respective class (as ‘leftovers’)

Media presets and source names are stored as arrays in their correct orders. Gravities and geometries are stored in a hash, keyed by their relevant media presets. Note that the base image will have a media preset of nil, which is a perfectly fine hash key.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_params) ⇒ TagParser

Returns a new instance of TagParser.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 24

def initialize(raw_params)
  @raw_params = raw_params
  @params = split_params

  @media_presets = []
  @source_names = []
  @geometries = {}
  @gravities = {}

  parse_params
end

Instance Attribute Details

#geometriesObject (readonly)

Returns the value of attribute geometries.



21
22
23
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 21

def geometries
  @geometries
end

#gravitiesObject (readonly)

Returns the value of attribute gravities.



21
22
23
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 21

def gravities
  @gravities
end

#leftoversObject (readonly)

Returns the value of attribute leftovers.



21
22
23
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 21

def leftovers
  @leftovers
end

#media_presetsObject (readonly)

Returns the value of attribute media_presets.



21
22
23
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 21

def media_presets
  @media_presets
end

#preset_nameObject (readonly)

Returns the value of attribute preset_name.



21
22
23
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 21

def preset_name
  @preset_name
end

#source_namesObject (readonly)

Returns the value of attribute source_names.



21
22
23
# File 'lib/jekyll_picture_tag/instructions/tag_parser.rb', line 21

def source_names
  @source_names
end