Class: Dimples::Site
- Inherits:
-
Object
- Object
- Dimples::Site
- Defined in:
- lib/dimples/site.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ generation: { overwrite_directory: false }, paths: { posts: "posts" } }
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#config ⇒ Object
Returns the value of attribute config.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#posts ⇒ Object
Returns the value of attribute posts.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(source_path, output_path, config) ⇒ Site
constructor
A new instance of Site.
Constructor Details
#initialize(source_path, output_path, config) ⇒ Site
Returns a new instance of Site.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dimples/site.rb', line 19 def initialize(source_path, output_path, config) @paths = { source: File.(source_path || Dir.pwd), destination: File.(output_path || File.join(Dir.pwd, "site")) } @config = DEFAULT_CONFIG @config.merge!(config) if config&.is_a?(Hash) %w[pages posts static templates].each do |type| @paths[type.to_sym] = File.join(@paths[:source], type) end scan_posts scan_pages scan_templates end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
17 18 19 |
# File 'lib/dimples/site.rb', line 17 def categories @categories end |
#config ⇒ Object
Returns the value of attribute config.
17 18 19 |
# File 'lib/dimples/site.rb', line 17 def config @config end |
#pages ⇒ Object
Returns the value of attribute pages.
17 18 19 |
# File 'lib/dimples/site.rb', line 17 def pages @pages end |
#posts ⇒ Object
Returns the value of attribute posts.
17 18 19 |
# File 'lib/dimples/site.rb', line 17 def posts @posts end |
Class Method Details
.generate(source_path, output_path, config) ⇒ Object
13 14 15 |
# File 'lib/dimples/site.rb', line 13 def self.generate(source_path, output_path, config) new(source_path, output_path, config).generate end |
Instance Method Details
#generate ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dimples/site.rb', line 37 def generate if Dir.exist?(@paths[:destination]) unless @config.dig(:generation, :overwrite_directory) raise GenerationError.new("The site directory (#{@paths[:destination]}) already exists.") end FileUtils.rm_rf(@paths[:destination]) end Dir.mkdir(@paths[:destination]) generate_posts generate_pages generate_categories copy_assets end |