Module: PictureTag

Defined in:
lib/jekyll-4-picture-tag/instructions.rb,
lib/jekyll-4-picture-tag.rb,
lib/jekyll-4-picture-tag/utils.rb,
lib/jekyll-4-picture-tag/version.rb,
lib/jekyll-4-picture-tag/source_image.rb,
lib/jekyll-4-picture-tag/srcsets/width.rb,
lib/jekyll-4-picture-tag/srcsets/basics.rb,
lib/jekyll-4-picture-tag/output_formats/img.rb,
lib/jekyll-4-picture-tag/instructions/preset.rb,
lib/jekyll-4-picture-tag/output_formats/auto.rb,
lib/jekyll-4-picture-tag/srcsets/pixel_ratio.rb,
lib/jekyll-4-picture-tag/output_formats/basics.rb,
lib/jekyll-4-picture-tag/output_formats/picture.rb,
lib/jekyll-4-picture-tag/instructions/tag_parser.rb,
lib/jekyll-4-picture-tag/output_formats/data_img.rb,
lib/jekyll-4-picture-tag/output_formats/data_auto.rb,
lib/jekyll-4-picture-tag/output_formats/direct_url.rb,
lib/jekyll-4-picture-tag/instructions/configuration.rb,
lib/jekyll-4-picture-tag/output_formats/data_picture.rb,
lib/jekyll-4-picture-tag/instructions/html_attributes.rb,
lib/jekyll-4-picture-tag/output_formats/data_attributes.rb

Overview

Allows us to access settings as methods on PictureTag itself.

Defined Under Namespace

Modules: Instructions, OutputFormats, Srcsets, Utils Classes: Picture, SourceImage

Constant Summary collapse

ROOT_PATH =
__dir__
VERSION =
'1.0.1'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 9

def config
  @config
end

.contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 9

def context
  @context
end

.html_attributesObject (readonly)

Returns the value of attribute html_attributes.



9
10
11
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 9

def html_attributes
  @html_attributes
end

.paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 9

def params
  @params
end

.presetObject (readonly)

Returns the value of attribute preset.



9
10
11
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 9

def preset
  @preset
end

Class Method Details

.build_source_url(filename) ⇒ Object



75
76
77
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 75

def build_source_url(filename)
  @config.build_source_url(filename)
end

.build_url(filename) ⇒ Object



71
72
73
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 71

def build_url(filename)
  @config.build_url(filename)
end

.dest_dirObject



67
68
69
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 67

def dest_dir
  @config.dest_dir
end

.fallback_formatObject



88
89
90
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 88

def fallback_format
  @preset.fallback_format
end

.fallback_widthObject



92
93
94
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 92

def fallback_width
  @preset.fallback_width
end

.init(raw_tag_params, context) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 11

def init(raw_tag_params, context)
  @context = context

  # Create global config (big picture). Config class loads jekyll
  # data/config files, and the j-p-t defaults from included yml files.
  @config = Instructions::Configuration.new

  # Parse tag params. We must do this before setting the preset, because
  # it's one of the params.
  @params = Instructions::TagParser.new(raw_tag_params)

  # Create preset. Takes preset name from params, merges associated settings
  # with default values.
  @preset = Instructions::Preset.new

  # Create HTML attributes. Depends on both the preset and tag params, so
  # we must do this after creating both.
  @html_attributes = Instructions::HTMLAttributeSet.new(
    @params.html_attributes_raw
  )

  # Keep our generated files
  Utils.keep_files
end

.media_presetsObject

Media query presets. It’s really just a hash, and there are no default values, so extracting it to its own class is overkill.



48
49
50
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 48

def media_presets
  site.data.dig('picture', 'media_presets') || {}
end

.nomarkdown?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 79

def nomarkdown?
  @config.nomarkdown?
end

.pageObject

Page which tag is called from



42
43
44
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 42

def page
  @context.registers[:page]
end

.preset_nameObject

Params forwarding



97
98
99
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 97

def preset_name
  @params.preset_name
end

.siteObject

Global site data



37
38
39
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 37

def site
  @context.registers[:site]
end

.source_dirObject

Config Forwarding



63
64
65
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 63

def source_dir
  @config.source_dir
end

.source_imagesObject



101
102
103
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 101

def source_images
  @params.source_images
end

.widths(media) ⇒ Object

Preset forwarding



84
85
86
# File 'lib/jekyll-4-picture-tag/instructions.rb', line 84

def widths(media)
  @preset.widths(media)
end