Class: Reacco::Readme
- Inherits:
-
Object
- Object
- Reacco::Readme
- Includes:
- Filters::Brief, Filters::HeadingID, Filters::Hgroup, Filters::Literate, Filters::PreLang, Filters::Sections, Filters::TOC
- Defined in:
- lib/reacco/readme.rb
Instance Method Summary collapse
- #api_blocks ⇒ Object
-
#doc(options = {}) ⇒ Object
### doc [method] Returns HTML as a Nokogiri document.
-
#exists? ⇒ Boolean
### exists? [method] Returns true if the file (given in the constructor) exists.
-
#file ⇒ Object
### file [method] The path to the README file.
- #file=(file) ⇒ Object
-
#github ⇒ Object
### github [method] Returns the GitHub URL, or nil if not applicable.
-
#html ⇒ Object
### html [method] Returns body’s inner HTML.
-
#initialize(options = {}) ⇒ Readme
constructor
A new instance of Readme.
-
#inject_api_block(html) ⇒ Object
### inject_api_block [method] Adds an API block.
-
#locals ⇒ Object
Returns locals for the template.
-
#raw ⇒ Object
### raw [method] Returns raw Markdown markup.
-
#raw_html ⇒ Object
### raw_html [method] Raw HTML data.
- #raw_html=(str) ⇒ Object
-
#switches ⇒ Object
### switches [method] The switches, like ‘literate’ and ‘hgroup’.
-
#title ⇒ Object
### title [method] Returns a string of the title of the document (the first h1).
- #title? ⇒ Boolean
Methods included from Filters::TOC
#linkify, #make_section, #make_toc
Methods included from Filters::HeadingID
Methods included from Filters::PreLang
Methods included from Filters::Literate
Methods included from Filters::Hgroup
Methods included from Filters::Sections
Methods included from Filters::Brief
Constructor Details
#initialize(options = {}) ⇒ Readme
Returns a new instance of Readme.
5 6 7 8 |
# File 'lib/reacco/readme.rb', line 5 def initialize(={}) @file = .delete(:file) if [:file] @options = end |
Instance Method Details
#api_blocks ⇒ Object
67 68 69 |
# File 'lib/reacco/readme.rb', line 67 def api_blocks @api_blocks ||= "" end |
#doc(options = {}) ⇒ Object
### doc [method] Returns HTML as a Nokogiri document.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/reacco/readme.rb', line 73 def doc(={}) @doc ||= begin add_api(api_blocks) html = Nokogiri::HTML(raw_html) html = pre_lang(html) html = heading_id(html) html = wrap_hgroup(html) html = move_pre(html) if @options[:literate] html = brief_first_p(html) html = section_wrap(html) html = make_toc(html) if @options[:toc] html end end |
#exists? ⇒ Boolean
### exists? [method] Returns true if the file (given in the constructor) exists.
28 29 30 |
# File 'lib/reacco/readme.rb', line 28 def exists? file && File.exists?(file) end |
#file ⇒ Object
### file [method] The path to the README file. Returns nil if not available.
12 13 14 |
# File 'lib/reacco/readme.rb', line 12 def file @file ||= (Dir['README.*'].first || Dir['readme.*'].first || Dir['README'].first) end |
#file=(file) ⇒ Object
16 17 18 |
# File 'lib/reacco/readme.rb', line 16 def file=(file) @file = file end |
#github ⇒ Object
### github [method] Returns the GitHub URL, or nil if not applicable.
98 99 100 |
# File 'lib/reacco/readme.rb', line 98 def github "https://github.com/#{@options[:github]}" if @options[:github] end |
#html ⇒ Object
### html [method] Returns body’s inner HTML.
92 93 94 |
# File 'lib/reacco/readme.rb', line 92 def html doc.at_css('body').inner_html end |
#inject_api_block(html) ⇒ Object
### inject_api_block [method] Adds an API block. Takes an ‘html` argument.
63 64 65 |
# File 'lib/reacco/readme.rb', line 63 def inject_api_block(html) @api_blocks = "#{api_blocks}\n#{html}\n" end |
#locals ⇒ Object
Returns locals for the template.
103 104 105 106 107 |
# File 'lib/reacco/readme.rb', line 103 def locals { :title => title, :body_class => switches.join(' '), :github => github } end |
#raw ⇒ Object
### raw [method] Returns raw Markdown markup.
34 35 36 |
# File 'lib/reacco/readme.rb', line 34 def raw @raw ||= File.read(file) end |
#raw_html ⇒ Object
### raw_html [method] Raw HTML data.
53 54 55 |
# File 'lib/reacco/readme.rb', line 53 def raw_html @raw_html ||= markdown.render(raw) end |
#raw_html=(str) ⇒ Object
57 58 59 |
# File 'lib/reacco/readme.rb', line 57 def raw_html=(str) @raw_html = str end |
#switches ⇒ Object
### switches [method] The switches, like ‘literate’ and ‘hgroup’. Returns an array of strings.
22 23 24 |
# File 'lib/reacco/readme.rb', line 22 def switches @options.keys.map { |k| k.to_s } end |
#title ⇒ Object
### title [method] Returns a string of the title of the document (the first h1).
40 41 42 43 44 45 |
# File 'lib/reacco/readme.rb', line 40 def title @title ||= begin h1 = (h1 = doc.at_css('h1')) && h1.text h1 || File.basename(Dir.pwd) end end |
#title? ⇒ Boolean
47 48 49 |
# File 'lib/reacco/readme.rb', line 47 def title? title.to_s.size > 0 end |