Class: Dimples::Site
- Inherits:
-
Object
- Object
- Dimples::Site
- Defined in:
- lib/dimples/site.rb
Overview
A class representing a single generated website.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #categories ⇒ Object
- #data ⇒ Object
- #generate ⇒ Object
-
#initialize(config: {}) ⇒ Site
constructor
A new instance of Site.
- #pages ⇒ Object
- #posts ⇒ Object
- #templates ⇒ Object
Constructor Details
#initialize(config: {}) ⇒ Site
Returns a new instance of Site.
17 18 19 |
# File 'lib/dimples/site.rb', line 17 def initialize(config: {}) @config = Config.new(config) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/dimples/site.rb', line 11 def config @config end |
Class Method Details
.generate(config: {}) ⇒ Object
13 14 15 |
# File 'lib/dimples/site.rb', line 13 def self.generate(config: {}) new(config: config).generate end |
Instance Method Details
#categories ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dimples/site.rb', line 58 def categories @categories ||= {}.tap do |categories| posts.each do |post| post.categories.each do |category| categories[category] ||= [] categories[category].append(post) end end end end |
#data ⇒ Object
52 53 54 55 56 |
# File 'lib/dimples/site.rb', line 52 def data @data ||= scan_path(path: @config.source_paths[:data], extension: '.json') do |path| Context.from_hash(JSON.parse(File.read(path))) end end |
#generate ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/dimples/site.rb', line 21 def generate prepare_output_directory generate_posts generate_categories generate_pages copy_assets end |
#pages ⇒ Object
39 40 41 42 43 |
# File 'lib/dimples/site.rb', line 39 def pages @pages ||= source_files(key: :pages, extension: 'erb').map do |path| Dimples::Template.new(site: self, path: path) end end |
#posts ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dimples/site.rb', line 31 def posts @posts ||= source_files(key: :posts, extension: 'markdown').map do |path| Dimples::Post.new(site: self, path: path) end .sort_by!(&:date) .reverse! end |
#templates ⇒ Object
45 46 47 48 49 50 |
# File 'lib/dimples/site.rb', line 45 def templates @templates ||= source_files(key: :templates, extension: 'erb').to_h do |path| key = File.basename(flatten_source_path(path:, key: :templates), '.erb').to_sym [key, Dimples::Template.new(site: self, path: path)] end end |