Class: Leandocument::Document
- Inherits:
-
Object
- Object
- Leandocument::Document
- Defined in:
- lib/leandocument/document.rb
Constant Summary collapse
- SETTING_FILE_NAME =
"settings.yml"
- SUPPORT_EXTENSIONS =
%w(md textile markdown mdown rdoc org creole mediawiki rst rest)
Instance Attribute Summary collapse
-
#base_path ⇒ Object
- lang
-
Document language.
-
#browsers ⇒ Object
- lang
-
Document language.
-
#childs ⇒ Object
- lang
-
Document language.
-
#commit ⇒ Object
- lang
-
Document language.
-
#error_message ⇒ Object
- lang
-
Document language.
-
#extension ⇒ Object
- lang
-
Document language.
-
#filename ⇒ Object
- lang
-
Document language.
-
#indent ⇒ Object
- lang
-
Document language.
-
#lang ⇒ Object
- lang
-
Document language.
-
#repository ⇒ Object
- lang
-
Document language.
-
#settings ⇒ Object
- lang
-
Document language.
-
#web_path ⇒ Object
- lang
-
Document language.
Instance Method Summary collapse
-
#content ⇒ Object
Return file content or blank string ==== Return File content.
- #e ⇒ Object
- #e? ⇒ Boolean
-
#initialize(options = {}) ⇒ Document
constructor
Generate Document class.
- #title ⇒ Object
-
#to_html ⇒ Object
Generate HTML content.
- #toc ⇒ Object
- #toc=(toc) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Document
Generate Document class.
Args
- options
-
lang:Default document language. base_path: Document path. indent: Document indent level.
Return
New Leandocument Document class.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/leandocument/document.rb', line 23 def initialize( = {}) self.base_path = [:base_path] || Dir.pwd self.settings = [:settings] || load_config self.lang = [:lang] || setting_value("settings", "default_locale") self.web_path = "#{[:web_path]}/" self.indent = [:indent] || 1 self.extension = get_extension self.filename = [:filename] || file_name self.childs = [] self.browsers = [] self.repository = [:repository] self.commit = [:commit] end |
Instance Attribute Details
#base_path ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def base_path @base_path end |
#browsers ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def browsers @browsers end |
#childs ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def childs @childs end |
#commit ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def commit @commit end |
#error_message ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def @error_message end |
#extension ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def extension @extension end |
#filename ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def filename @filename end |
#indent ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def indent @indent end |
#lang ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def lang @lang end |
#repository ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def repository @repository end |
#settings ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def settings @settings end |
#web_path ⇒ Object
16 17 18 |
# File 'lib/leandocument/document.rb', line 16 def web_path @web_path end |
Instance Method Details
#content ⇒ Object
Return file content or blank string
Return
File content. Or blank string if file not found.
97 98 99 100 101 102 103 104 105 |
# File 'lib/leandocument/document.rb', line 97 def content return @content if @content if self.commit @content = find_content ? find_content.data.force_encoding('UTF-8') : "" else @content = File.exist?(self.file_path) ? open(self.file_path).read.force_encoding('UTF-8') : "" end @content end |
#e ⇒ Object
44 45 46 |
# File 'lib/leandocument/document.rb', line 44 def e self. end |
#e? ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/leandocument/document.rb', line 37 def e? return (self. = "File not found. #{file_path}(#{SUPPORT_EXTENSIONS.join("|")})") unless get_extension return (self. = "Something wrong setting file. #{config_file_path}") unless self.settings return (self. = "File convert error. Please check file encoding. LeanDocument is allow only UTF-8. #{file_path}") unless self.title nil end |
#title ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/leandocument/document.rb', line 72 def title return "" unless render begin render.title rescue ArgumentError => e nil end end |
#to_html ⇒ Object
Generate HTML content.
Return
HTML content.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/leandocument/document.rb', line 51 def to_html return "" unless file_name return e if e? page = render.to_html path = File.dirname(file_path) # Get child content. # A reflexive. files(path).each do |file| doc = Document.new :base_path => self.base_path, :lang => self.lang, :indent => self.indent, :settings => self.settings, :web_path => self.web_path, :commit => self.commit, :repository => self.repository, :filename => file self.browsers << doc page += doc.to_html end dirs(path).each do |dir| # Plus one indent from parent. Change h[1-6] tag to h[2-7] if indent is 1. doc = Document.new :base_path => dir, :lang => self.lang, :indent => self.indent + 1, :settings => self.settings, :web_path => self.web_path[0..-2] + dir.gsub(self.base_path, ""), :commit => self.commit, :repository => self.repository self.childs << doc page += doc.to_html end page end |
#toc ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/leandocument/document.rb', line 81 def toc return @toc if @toc @toc = render.toc self.childs.each do |doc| @toc += doc.toc end @toc end |
#toc=(toc) ⇒ Object
90 91 92 |
# File 'lib/leandocument/document.rb', line 90 def toc=(toc) @toc += toc end |