Class: JekyllIS::Images::Kramdown::Figure
- Defined in:
- lib/jekyll-is/images/kramdown/figure.rb
Constant Summary collapse
- MODES =
{ 'grid' => { child: 'cell', label: 'grid', display: 'grid', navbar: false }, 'slides' => { child: 'slide', label: 'slides', display: 'flex', navbar: true } }
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#modes ⇒ Object
readonly
Returns the value of attribute modes.
-
#shaped ⇒ Object
readonly
Returns the value of attribute shaped.
-
#shift ⇒ Object
readonly
Returns the value of attribute shift.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes inherited from Value
#attrs, #classes, #context, #flags, #id, #styles
Instance Method Summary collapse
- #apply(element) ⇒ Object
- #category ⇒ Object
- #gallery? ⇒ Boolean
-
#initialize(context) ⇒ Figure
constructor
A new instance of Figure.
- #single? ⇒ Boolean
-
#to_html ⇒ Object
TODO: Подумать над тем, чтобы вынести разные представления галерей в классы...
- #type ⇒ Object
Methods inherited from Value
Constructor Details
#initialize(context) ⇒ Figure
Returns a new instance of Figure.
12 13 14 15 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 12 def initialize context super(context) @children = [] end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
25 26 27 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 25 def caption @caption end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
10 11 12 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 10 def children @children end |
#modes ⇒ Object (readonly)
Returns the value of attribute modes.
25 26 27 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 25 def modes @modes end |
#shaped ⇒ Object (readonly)
Returns the value of attribute shaped.
25 26 27 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 25 def shaped @shaped end |
#shift ⇒ Object (readonly)
Returns the value of attribute shift.
25 26 27 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 25 def shift @shift end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
25 26 27 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 25 def width @width end |
Instance Method Details
#apply(element) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 27 def apply element super(element) @id ||= gen_id @caption = @attrs.delete('caption') @caption_position = @attrs.delete('caption-position') @shift = @attrs.delete('shift')&.to_i @up = @attrs.delete('up')&.to_i @width = @attrs.delete('width')&.to_i @modes = @attrs.delete('modes')&.split(',')&.map(&:strip) || @context.config('gallery', 'modes')&.split(',') || [] element.children.each do |child| if [ :a, :img ].include?(child.type) image = JekyllIS::Images::Kramdown::Image::new @context, figure: self image.apply child @children << image end end if single? image = @children.first @caption ||= image.caption @caption_position ||= image.caption_position @attrs = image.attrs.merge(@attrs) # «Крадём» классы и флаги. @flags.merge image.flags image.flags.clear @classes.merge image.classes image.classes.clear @shaped = @flags.delete?('shape') @shift ||= image.shift @up ||= image.up @width ||= image.width end if gallery? @caption_position ||= @context.config('gallery', 'caption_position') else @caption_position ||= @context.config('caption_position') end if @children.size == 0 @context.error "Invalid figure (without images) on page #{ @context.page.relative_path.inspect }" end if @children.size > 1 && @modes.empty? @context.error "Invalid gallery (without modes) on page #{ @context.page.relative_path.inspect }" end end |
#category ⇒ Object
8 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 8 def category = :block |
#gallery? ⇒ Boolean
21 22 23 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 21 def gallery? @children.size > 1 end |
#single? ⇒ Boolean
17 18 19 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 17 def single? @children.size == 1 end |
#to_html ⇒ Object
TODO: Подумать над тем, чтобы вынести разные представления галерей в классы...
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 92 def to_html case @children.size when 0 @context.error "Invalid figure (without images) on page #{ @context.page.relative_path.inspect }" '' when 1 generate_simple_html else if @modes.empty? @context.error "Invalid gallery (without modes) on page #{ @context.page.relative_path.inspect }" '' else @context.page.data['__is_images_has_galleries'] = true hide = false gallery = @modes.map do |mode| item = generate_gallery_html(mode, hide) hide = true item end.join("\n") generate_outer_html gallery end end end |
#type ⇒ Object
7 |
# File 'lib/jekyll-is/images/kramdown/figure.rb', line 7 def type = :is_figure |