Class: MadDoc::Runner
- Inherits:
-
Object
- Object
- MadDoc::Runner
- Defined in:
- lib/maddoc/runner.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #asset(pathname) ⇒ Object
- #body ⇒ Object
- #environment ⇒ Object
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #parse!(argv) ⇒ Object
- #run! ⇒ Object
- #template ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
17 18 19 20 21 22 23 |
# File 'lib/maddoc/runner.rb', line 17 def initialize argv parse!(argv).tap do || @title = .title end @source = ARGF.read unless argv.empty? and $stdin.tty? end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
15 16 17 |
# File 'lib/maddoc/runner.rb', line 15 def title @title end |
Class Method Details
.run(argv) ⇒ Object
97 98 99 |
# File 'lib/maddoc/runner.rb', line 97 def self.run argv new(argv).run! end |
Instance Method Details
#asset(pathname) ⇒ Object
26 27 28 |
# File 'lib/maddoc/runner.rb', line 26 def asset pathname environment[pathname].to_s end |
#body ⇒ Object
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 |
# File 'lib/maddoc/runner.rb', line 39 def body renderer = Class.new(Redcarpet::Render::SmartyHTML) do def block_code(code, lang) lang = lang && lang.split.first || "text" ( Pygments.highlight(code, { :lexer => lang, :options => { :encoding => 'utf-8' } }), lang ) end def (code, lang) code = code.sub(/<pre>/,'<pre><code class="' + lang + '">') code = code.sub(/<\/pre>/,"</code></pre>") end end.new({ :with_toc_data => true }) Redcarpet::Markdown.new(renderer, { :no_intra_emphasis => true, :tables => true, :fenced_code_blocks => true, :autolink => true, :strikethrough => true, :lax_spacing => true }).render(@source) end |
#environment ⇒ Object
31 32 33 34 35 36 |
# File 'lib/maddoc/runner.rb', line 31 def environment @environment ||= Sprockets::Environment.new(MadDoc.root.join('templates')).tap do |env| env.append_path 'assets/stylesheets' env.css_compressor = :sass end end |
#parse!(argv) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/maddoc/runner.rb', line 72 def parse! argv = OpenStruct.new({ :title => 'Untitled mad documentation' }) OptionParser.new do |opts| opts.on('-t', '--title [TITLE]', 'Title') do |title| .title = title.strip end end.parse! argv end |
#run! ⇒ Object
92 93 94 |
# File 'lib/maddoc/runner.rb', line 92 def run! puts template.render(self) end |