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"
- ENV_ROOT =
"FORESITE_ROOT"
- PATH_TO_DEFAULTS =
File.join(__dir__, "skeleton")
- VERSION =
"1.3.0"
Class Method Summary collapse
- .copy_templates ⇒ Object
- .get_path_to_erb ⇒ Object
- .get_path_to_erb_file(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_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
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/foresite.rb', line 112 def self.copy_templates [FILENAME_POST_MD, FILENAME_WRAPPER_HTML, FILENAME_LIST_HTML].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
51 52 53 |
# File 'lib/foresite.rb', line 51 def self.get_path_to_erb File.join(get_path_to_root, DIRNAME_ERB) end |
.get_path_to_erb_file(file) ⇒ Object
55 56 57 |
# File 'lib/foresite.rb', line 55 def self.get_path_to_erb_file(file) File.join(get_path_to_erb, file) end |
.get_path_to_index_file ⇒ Object
67 68 69 |
# File 'lib/foresite.rb', line 67 def self.get_path_to_index_file File.join(get_path_to_root, "index.html") end |
.get_path_to_md ⇒ Object
43 44 45 |
# File 'lib/foresite.rb', line 43 def self.get_path_to_md File.join(get_path_to_root, DIRNAME_MARKDOWN) end |
.get_path_to_md_file(file) ⇒ Object
59 60 61 |
# File 'lib/foresite.rb', line 59 def self.get_path_to_md_file(file) File.join(get_path_to_md, file) end |
.get_path_to_out ⇒ Object
47 48 49 |
# File 'lib/foresite.rb', line 47 def self.get_path_to_out File.join(get_path_to_root, DIRNAME_POST) end |
.get_path_to_out_file(file) ⇒ Object
63 64 65 |
# File 'lib/foresite.rb', line 63 def self.get_path_to_out_file(file) File.join(get_path_to_out, file) end |
.get_path_to_root ⇒ Object
25 26 27 |
# File 'lib/foresite.rb', line 25 def self.get_path_to_root ENV[ENV_ROOT] || Dir.pwd end |
.relative_path(full_path) ⇒ Object
71 72 73 |
# File 'lib/foresite.rb', line 71 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
75 76 77 |
# File 'lib/foresite.rb', line 75 def self.render_erb_file(file, vars) Renderer.render(get_path_to_erb_file(file), vars) end |
.render_post(title, date_ymd) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/foresite.rb', line 79 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
86 87 88 89 90 91 |
# File 'lib/foresite.rb', line 86 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
93 94 95 96 97 98 99 |
# File 'lib/foresite.rb', line 93 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
29 30 31 |
# File 'lib/foresite.rb', line 29 def self.root_exists? Dir.exist?(get_path_to_root) end |
.root_writable? ⇒ Boolean
33 34 35 |
# File 'lib/foresite.rb', line 33 def self.root_writable? File.writable?(get_path_to_root) end |
.subdirectories_exist? ⇒ Boolean
37 38 39 40 41 |
# File 'lib/foresite.rb', line 37 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
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/foresite.rb', line 101 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 |