Class: PictureTag::Parsers::TagParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_picture_tag/parsers/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 keep. HTML attributes are handed off to its respective class (as 'leftovers')

Media presets and source names are stored as arrays in their correct orders. Crop settings 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.



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

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

  @media_presets = []
  @source_names = []
  @keep = {}
  @crop = {}

  parse_params
end

Instance Attribute Details

#cropObject (readonly)

Returns the value of attribute crop.



20
21
22
# File 'lib/jekyll_picture_tag/parsers/tag_parser.rb', line 20

def crop
  @crop
end

#keepObject (readonly)

Returns the value of attribute keep.



20
21
22
# File 'lib/jekyll_picture_tag/parsers/tag_parser.rb', line 20

def keep
  @keep
end

#leftoversObject (readonly)

Returns the value of attribute leftovers.



20
21
22
# File 'lib/jekyll_picture_tag/parsers/tag_parser.rb', line 20

def leftovers
  @leftovers
end

#media_presetsObject (readonly)

Returns the value of attribute media_presets.



20
21
22
# File 'lib/jekyll_picture_tag/parsers/tag_parser.rb', line 20

def media_presets
  @media_presets
end

#preset_nameObject (readonly)

Returns the value of attribute preset_name.



20
21
22
# File 'lib/jekyll_picture_tag/parsers/tag_parser.rb', line 20

def preset_name
  @preset_name
end

#source_namesObject (readonly)

Returns the value of attribute source_names.



20
21
22
# File 'lib/jekyll_picture_tag/parsers/tag_parser.rb', line 20

def source_names
  @source_names
end