Class: Docwu::Render
- Inherits:
-
Object
- Object
- Docwu::Render
- Defined in:
- lib/docwu/render.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#generate(options = {}) ⇒ Object
usage: ::Docwu::Render.generate( :content_data => ” ) options: - content_data - content_text - dest - template.
Class Method Details
.generate(*args) ⇒ Object
10 11 12 |
# File 'lib/docwu/render.rb', line 10 def generate(*args) self.new.generate(*args) end |
Instance Method Details
#generate(options = {}) ⇒ Object
usage:
::Docwu::Render.generate(
:content_data => ''
)
options:
- content_data
- content_text
- dest
- template
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/docwu/render.rb', line 32 def generate(={}) content_data = [:content_data] || {} content_text = [:content_text] || '' content_result = '' dest = [:dest] template = [:template] # 读取标记类型 marktype = (content_data['marktype'] || 'markdown').to_s # 目录 _catalogs = [] case marktype when 'markdown' = [ :hard_wrap, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode, :tables, :footnotes, :superscript, :underline, :strikethrough, :space_after_headers, :quote, :highlight ] _html = ::RedcarpetCompat.new(content_text, *).to_html # markdown = Redcarpet::Markdown.new( # Redcarpet::Render::HTML, # :autolink => true, # :space_after_headers => true, # 头部必须有个空格 # :fenced_code_blocks => true, # ```括起来的代码段落 # :strikethrough => true, # ~~ 删除 # :superscript => true, # :underline => true, # :highlight => true, # :quote => true, # :footnotes => true, # :hard_wrap => true # ) # _html = markdown.render(content_text) # 获取一个html代码的目录结果 _catalogs_result = ::Docwu::Utils.html_catalogable(_html) _catalogs = _catalogs_result['catalogs'] content_result << ::Docwu::Utils.syntax_highlighter(_catalogs_result['html']) else # FIXME: no end content_data['page'] ||= {} # 正文 content_data['page']['content'] = content_result content_data['page']['content_present?'] = content_result.size > 0 # 目录 content_data['page']['catalogs'] = _catalogs ::Docwu::Utils.formated_hashed!(content_data) # pp content_data # puts "#{template}" # 页面的内容 ::Docwu::Utils.write_file dest, ::MustacheRender::Mustache.render(template, content_data) end |