Class: EasyDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_doc.rb

Defined Under Namespace

Classes: MakeDirectoryError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mkd_path, html_path) ⇒ EasyDoc

Returns a new instance of EasyDoc.

Raises:



36
37
38
39
40
41
42
# File 'lib/easy_doc.rb', line 36

def initialize(mkd_path,html_path)
  raise ArgumentError, 'mkd_path is invalid' unless File.directory?(mkd_path) && html_path.kind_of?(String)
  raise ArgumentError, 'html_path is invalid' unless html_path.kind_of?(String)
  @mkd_path  = File.expand_path(mkd_path ).gsub(/\/$/,"")
  @html_path = File.expand_path(html_path).gsub(/\/$/,"")
  init_config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



132
133
134
# File 'lib/easy_doc.rb', line 132

def config
  @config
end

Instance Method Details

#delete_htmls(quiet = true) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/easy_doc.rb', line 123

def delete_htmls(quiet=true)
  fs = deleted_markdown_files
  fs.each do |f|
    h = f.gsub(/\.mkd$/,'.html')
    puts "Removing: #{h}" unless quiet
    FileUtils.remove(html_expand_path(h))
  end
end

#init_configObject



44
45
46
47
48
49
50
# File 'lib/easy_doc.rb', line 44

def init_config
  @config    = { #Default config
                 :default_lang => "default"
               }
  @changed_config = changed_config
  @config.merge!(load_config)
end

#layoutObject



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
108
109
110
111
112
113
114
115
116
117
# File 'lib/easy_doc.rb', line 62

def layout
  if File.exist?("#{@mkd_path}/layout.erb")
    File.read("#{@mkd_path}/layout.erb")
  else
    ### Default layout  ###
    return "<html>\n<head>\n  <title><%= title %></title>\n  <style type=\"text/css\">\n    body {\n      font-family: sans-serif;\n      font-size: 18px;\n    }\n\n    h1 { font-size: 28px; }\n    h2 { font-size: 26px; }\n    h3 { font-size: 24px; }\n    h4 { font-size: 22px; }\n    h5 { font-size: 20px; }\n    h6 { font-size: 17px; }\n\n    .header {\n      padding-bottom: 10px;\n      border-bottom: 1px solid gray;\n      margin-bottom: 10px;\n    }\n\n    .lang_bar {\n      text-align: right;\n      font-size: 13px;\n    }\n\n    .title {\n      font-size: 24px;\n      margin-top: 5px;\n    }\n  </style>\n</head>\n<body>\n  <!-- Document rendered by easy_doc http://github.com/sorah/easy-doc -->\n  <div class=\"header\">\n    <div class=\"lang_bar\">\n      <%= lang_bar %>\n    </div>\n    <!--<div class=\"title\"><%= title %></div>-->\n  </div>\n  <div class=\"doc_body\">\n    <%= body %>\n  </div>\n</body>\n</html>\n    EOB\n    ######### End #########\n  end\nend\n"

#markdown_files(lp = true) ⇒ Object



119
120
121
# File 'lib/easy_doc.rb', line 119

def markdown_files(lp=true)
  Dir.glob("#{@mkd_path}/**/*.mkd").map{|x| lp ? mkd_local_path(x) : x }
end

#render(quiet = true, force = false) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/easy_doc.rb', line 52

def render(quiet=true,force=false)
  puts "Checking changed markdown files..." unless quiet
  f = (force || @changed_config.include?(:default_lang)) ? markdown_files : changed_markdown_files
  f.each do |n|
    puts "Rendering: #{n}" unless quiet
    render_file(n)
  end
  self
end