Module: Foresite
- Defined in:
- lib/foresite.rb,
lib/foresite/cli.rb,
lib/foresite/version.rb,
lib/foresite/renderer.rb
Defined Under Namespace
Constant Summary collapse
- DIRNAME_MARKDOWN =
"md"
- DIRNAME_POST =
"post"
- DIRNAME_ERB =
"erb"
- FILENAME_POST_MD =
"post.md.erb"
- FILENAME_WRAPPER_HTML =
"wrapper.html.erb"
- FILENAME_LIST_HTML =
"_list.html.erb"
- FILENAME_FEED_XML =
"feed.xml.erb"
- ENV_ROOT =
"FORESITE_ROOT"
- PATH_TO_DEFAULTS =
File.join(__dir__, "skeleton")
- VERSION =
"1.4.0"
Class Method Summary collapse
- .copy_templates ⇒ Object
- .get_path_to_erb ⇒ Object
- .get_path_to_erb_file(file) ⇒ Object
- .get_path_to_feed_file ⇒ Object
- .get_path_to_index_file ⇒ Object
- .get_path_to_md ⇒ Object
- .get_path_to_md_file(file) ⇒ Object
- .get_path_to_out ⇒ Object
- .get_path_to_out_file(file) ⇒ Object
- .get_path_to_root ⇒ Object
- .relative_path(full_path) ⇒ Object
- .render_erb_file(file, vars) ⇒ Object
- .render_feed(items, date_build_822) ⇒ Object
- .render_post(title, date_ymd) ⇒ Object
- .render_wrapped(title, markdown_content) ⇒ Object
- .render_wrapped_index(links) ⇒ Object
- .root_exists? ⇒ Boolean
- .root_writable? ⇒ Boolean
- .subdirectories_exist? ⇒ Boolean
- .touch_directories ⇒ Object
Class Method Details
.copy_templates ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/foresite.rb', line 124 def self.copy_templates [FILENAME_POST_MD, FILENAME_WRAPPER_HTML, FILENAME_LIST_HTML, FILENAME_FEED_XML].map do |filename| full_file_path = File.join(get_path_to_erb, filename) if File.exist?(full_file_path) "#{relative_path(full_file_path)} already exists" else File.copy_stream(File.join(PATH_TO_DEFAULTS, filename), full_file_path) "Created #{relative_path(full_file_path)}" end end end |
.get_path_to_erb ⇒ Object
52 53 54 |
# File 'lib/foresite.rb', line 52 def self.get_path_to_erb File.join(get_path_to_root, DIRNAME_ERB) end |
.get_path_to_erb_file(file) ⇒ Object
56 57 58 |
# File 'lib/foresite.rb', line 56 def self.get_path_to_erb_file(file) File.join(get_path_to_erb, file) end |
.get_path_to_feed_file ⇒ Object
72 73 74 |
# File 'lib/foresite.rb', line 72 def self.get_path_to_feed_file File.join(get_path_to_root, "feed.xml") end |
.get_path_to_index_file ⇒ Object
68 69 70 |
# File 'lib/foresite.rb', line 68 def self.get_path_to_index_file File.join(get_path_to_root, "index.html") end |
.get_path_to_md ⇒ Object
44 45 46 |
# File 'lib/foresite.rb', line 44 def self.get_path_to_md File.join(get_path_to_root, DIRNAME_MARKDOWN) end |
.get_path_to_md_file(file) ⇒ Object
60 61 62 |
# File 'lib/foresite.rb', line 60 def self.get_path_to_md_file(file) File.join(get_path_to_md, file) end |
.get_path_to_out ⇒ Object
48 49 50 |
# File 'lib/foresite.rb', line 48 def self.get_path_to_out File.join(get_path_to_root, DIRNAME_POST) end |
.get_path_to_out_file(file) ⇒ Object
64 65 66 |
# File 'lib/foresite.rb', line 64 def self.get_path_to_out_file(file) File.join(get_path_to_out, file) end |
.get_path_to_root ⇒ Object
26 27 28 |
# File 'lib/foresite.rb', line 26 def self.get_path_to_root ENV[ENV_ROOT] || Dir.pwd end |
.relative_path(full_path) ⇒ Object
76 77 78 |
# File 'lib/foresite.rb', line 76 def self.relative_path(full_path) full_path.gsub(get_path_to_root, "").gsub(Regexp.new("^#{File::SEPARATOR}"), "") end |
.render_erb_file(file, vars) ⇒ Object
80 81 82 |
# File 'lib/foresite.rb', line 80 def self.render_erb_file(file, vars) Renderer.render(get_path_to_erb_file(file), vars) end |
.render_feed(items, date_build_822) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/foresite.rb', line 106 def self.render_feed(items, date_build_822) render_erb_file(FILENAME_FEED_XML, { items: items.reverse, date_build_822: date_build_822 }) end |
.render_post(title, date_ymd) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/foresite.rb', line 84 def self.render_post(title, date_ymd) render_erb_file(FILENAME_POST_MD, { title: title, date_ymd: date_ymd }) end |
.render_wrapped(title, markdown_content) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/foresite.rb', line 91 def self.render_wrapped(title, markdown_content) render_erb_file(FILENAME_WRAPPER_HTML, { title: title, content: ::Kramdown::Document.new(markdown_content).to_html }) end |
.render_wrapped_index(links) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/foresite.rb', line 98 def self.render_wrapped_index(links) render_erb_file(FILENAME_WRAPPER_HTML, { content: render_erb_file(FILENAME_LIST_HTML, { links: links.reverse }) }) end |
.root_exists? ⇒ Boolean
30 31 32 |
# File 'lib/foresite.rb', line 30 def self.root_exists? Dir.exist?(get_path_to_root) end |
.root_writable? ⇒ Boolean
34 35 36 |
# File 'lib/foresite.rb', line 34 def self.root_writable? File.writable?(get_path_to_root) end |
.subdirectories_exist? ⇒ Boolean
38 39 40 41 42 |
# File 'lib/foresite.rb', line 38 def self.subdirectories_exist? [get_path_to_md, get_path_to_out, get_path_to_erb].all? do |path| Dir.exist?(path) end end |
.touch_directories ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/foresite.rb', line 113 def self.touch_directories [get_path_to_md, get_path_to_out, get_path_to_erb].map do |path| if Dir.exist?(path) "#{relative_path(path)}/ already exists" else Dir.mkdir(path) "Created #{relative_path(path)}/" end end end |