Sha256: 5d04a9a44e8ab199337313f753edaa358d29c91c53df0d33d117797aef0a056f

Contents?: true

Size: 923 Bytes

Versions: 18

Compression:

Stored size: 923 Bytes

Contents

module Kayessess

  # 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.
  class SectionExample
    attr_accessor :section, :html

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

    def extra_classes
      @options.class || ''
    end

    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

    def modifiers
      @section.modifiers
    end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
kayessess-0.2.11 lib/kayessess/section_example.rb
kayessess-0.2.10 lib/kayessess/section_example.rb
kayessess-0.2.9 lib/kayessess/section_example.rb
kayessess-0.2.8 lib/kayessess/section_example.rb
kayessess-0.2.7 lib/kayessess/section_example.rb
kayessess-0.2.5 lib/kayessess/section_example.rb
kayessess-0.2.4 lib/kayessess/section_example.rb
kayessess-0.2.3 lib/kayessess/section_example.rb
kayessess-0.2.2 lib/kayessess/section_example.rb
kayessess-0.2.1 lib/kayessess/section_example.rb
kayessess-0.2.0 lib/kayessess/section_example.rb
kayessess-0.1.6 lib/kayessess/section_example.rb
kayessess-0.1.5 lib/kayessess/section_example.rb
kayessess-0.1.4 lib/kayessess/section_example.rb
kayessess-0.1.3 lib/kayessess/section_example.rb
kayessess-0.1.2 lib/kayessess/section_example.rb
kayessess-0.1.1 lib/kayessess/section_example.rb
kayessess-0.1.0 lib/kayessess/section_example.rb