Class: Mdx::MdxRender

Inherits:
Redcarpet::Render::XHTML
  • Object
show all
Includes:
Rouge::Plugins::Redcarpet
Defined in:
lib/mdx.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMdxRender

Returns a new instance of MdxRender.



13
14
15
16
# File 'lib/mdx.rb', line 13

def initialize
  @level = 8
  super
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/mdx.rb', line 11

def title
  @title
end

Class Method Details

.load_templatesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mdx.rb', line 26

def self.load_templates
  @@templates = {}

  begin
    io = File.read(__FILE__).force_encoding(Encoding::UTF_8)
    app, data = io.gsub("\r\n", "\n").split(/^__END__$/, 2)
  rescue Errno::ENOENT
    app, data = nil
  end

  if data
    template = nil
    data.each_line do |line|
      if line =~ /^@@\s*(.*\S)\s*$/
        template = ''
        @@templates[$1.to_sym] = template
      elsif template
        template << line
      end
    end
  end

  @@default_style = Sass::Engine.new(@@templates[:style], syntax: :scss, style: :compressed).to_css
end

Instance Method Details

#header(title, level) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/mdx.rb', line 18

def header title, level
  if level < @level || !@title
    @title = title
    @level = level
  end
  "<h#{level}>#{title}</h#{level}>"
end

#postprocess(doc) ⇒ Object



51
52
53
54
# File 'lib/mdx.rb', line 51

def postprocess doc
  style = @style || @@default_style
  @@templates[:html] % [@title, style, doc]
end