Class: Kayessess::SectionExample

Inherits:
Object
  • Object
show all
Defined in:
lib/kayessess/section_example.rb

Overview

SectionExample is a untility class for helping to render Section Examples. It is passed into the section_example partial and then used as a view object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section, html, options = {}) ⇒ SectionExample

Returns a new instance of SectionExample.



8
9
10
11
12
# File 'lib/kayessess/section_example.rb', line 8

def initialize(section, html, options = {})
  @section = section
  @html    = html
  @options = options
end

Instance Attribute Details

#htmlObject

Returns the value of attribute html.



6
7
8
# File 'lib/kayessess/section_example.rb', line 6

def html
  @html
end

#sectionObject

Returns the value of attribute section.



6
7
8
# File 'lib/kayessess/section_example.rb', line 6

def section
  @section
end

Instance Method Details

#extra_classesObject



14
15
16
# File 'lib/kayessess/section_example.rb', line 14

def extra_classes
  @options.class || ''
end

#html_for_modifier(modifier) ⇒ Object



32
33
34
# File 'lib/kayessess/section_example.rb', line 32

def html_for_modifier(modifier)
  html.gsub('$modifier_class', "#{modifier.class_name}").html_safe
end

#html_unescapedObject



18
19
20
21
22
23
24
25
26
# File 'lib/kayessess/section_example.rb', line 18

def html_unescaped
  cleaned_html = @html
    .gsub('$modifier_class', '')
    .gsub(/class="([\w\s-]+)"/) {|matches| "class=\"#{$1.strip}\"" }
    .gsub(' class=""', '')
    .gsub(' style=".+"', '')
    .gsub(/^$\n/, '')
  Kayessess.markdownerize("```html\n#{cleaned_html}\n```")
end

#modifiersObject



28
29
30
# File 'lib/kayessess/section_example.rb', line 28

def modifiers
  @section.modifiers
end