Class: Dropsite::Site
- Inherits:
-
Object
- Object
- Dropsite::Site
- Defined in:
- lib/dropsite/site.rb
Overview
Main site builder class. Some inspiration here from Jekyll (github.com/mojombo/jekyll).
Instance Attribute Summary collapse
-
#disabled_plugins ⇒ Object
readonly
Returns the value of attribute disabled_plugins.
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#public_dir ⇒ Object
readonly
Returns the value of attribute public_dir.
-
#site_files_dir ⇒ Object
readonly
Returns the value of attribute site_files_dir.
-
#site_tree ⇒ Object
readonly
Returns the value of attribute site_tree.
Instance Method Summary collapse
- #assets_dir ⇒ Object
-
#clean ⇒ Object
Cleans up files previously generated by Dropsite (or at least ones) that look like they are.
-
#initialize(config) ⇒ Site
constructor
A new instance of Site.
- #notice(message) ⇒ Object
- #process ⇒ Object
- #read ⇒ Object
- #render ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(config) ⇒ Site
Returns a new instance of Site.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dropsite/site.rb', line 8 def initialize(config) if config.is_a? String @public_dir = config @exclude, @disabled_plugins = [], [] @quiet = false else @config = config.clone @public_dir = config[:public_dir] @exclude = config[:exclude] || [] @disabled_plugins = config[:disabled_plugins] || [] @quiet = config[:quiet] || false end @site_tree = nil @site_files_dir = File.join(@public_dir, 'dropsite') end |
Instance Attribute Details
#disabled_plugins ⇒ Object (readonly)
Returns the value of attribute disabled_plugins.
6 7 8 |
# File 'lib/dropsite/site.rb', line 6 def disabled_plugins @disabled_plugins end |
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
6 7 8 |
# File 'lib/dropsite/site.rb', line 6 def exclude @exclude end |
#public_dir ⇒ Object (readonly)
Returns the value of attribute public_dir.
6 7 8 |
# File 'lib/dropsite/site.rb', line 6 def public_dir @public_dir end |
#site_files_dir ⇒ Object (readonly)
Returns the value of attribute site_files_dir.
6 7 8 |
# File 'lib/dropsite/site.rb', line 6 def site_files_dir @site_files_dir end |
#site_tree ⇒ Object (readonly)
Returns the value of attribute site_tree.
6 7 8 |
# File 'lib/dropsite/site.rb', line 6 def site_tree @site_tree end |
Instance Method Details
#assets_dir ⇒ Object
69 70 71 |
# File 'lib/dropsite/site.rb', line 69 def assets_dir File.join(@site_files_dir, 'dropsite-assets') end |
#clean ⇒ Object
Cleans up files previously generated by Dropsite (or at least ones) that look like they are. By default this will be an index.html file and dropsite directory in the Public directory root.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dropsite/site.rb', line 35 def clean if File.exist?(@site_files_dir) notice "Deleting existing site files dir at #{@site_files_dir}" FileUtils.rm_rf(@site_files_dir) end index_file = File.join(@public_dir, 'index.html') if File.exist?(index_file) notice "Deleting existing top-level index at #{index_file}" File.delete(index_file) end end |
#notice(message) ⇒ Object
73 74 75 76 |
# File 'lib/dropsite/site.rb', line 73 def notice() return if @quiet warn "#{File.basename($0)}: #{}" end |
#process ⇒ Object
25 26 27 28 29 30 |
# File 'lib/dropsite/site.rb', line 25 def process clean read render write end |
#read ⇒ Object
48 49 50 |
# File 'lib/dropsite/site.rb', line 48 def read @site_tree = read_directory end |
#render ⇒ Object
52 53 54 |
# File 'lib/dropsite/site.rb', line 52 def render site_tree.render end |
#write ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dropsite/site.rb', line 56 def write notice "Creating site files dir at #{site_files_dir}" Dir.mkdir(site_files_dir) site_tree.write Dir.mkdir(assets_dir) DirRenderer.renderers.each do |r| if File.exist? r.assets_dir FileUtils.cp_r(r.assets_dir, File.join(assets_dir, Dropsite.underscorize(r.class.to_s))) end end end |