Class: Pagemaster::Site
- Inherits:
-
Object
- Object
- Pagemaster::Site
- Defined in:
- lib/pagemaster/site.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#collections ⇒ Object
readonly
Returns the value of attribute collections.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #config_from_file ⇒ Object
- #generate_pages ⇒ Object
-
#initialize(args, opts, config = nil) ⇒ Site
constructor
A new instance of Site.
- #parse_collections ⇒ Object
Constructor Details
#initialize(args, opts, config = nil) ⇒ Site
Returns a new instance of Site.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pagemaster/site.rb', line 11 def initialize(args, opts, config = nil) @args = args @opts = opts @config = config || config_from_file @collections = parse_collections @collections_dir = @config.dig 'collections_dir' @source_dir = @config.dig 'source_dir' raise Error::MissingArgs, 'You must specify one or more collections after `jekyll pagemaster`' if @args.empty? raise Error::InvalidCollection, "Cannot find collection(s) #{@args} in config" if @collections.empty? end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/pagemaster/site.rb', line 7 def args @args end |
#collections ⇒ Object (readonly)
Returns the value of attribute collections.
7 8 9 |
# File 'lib/pagemaster/site.rb', line 7 def collections @collections end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/pagemaster/site.rb', line 7 def config @config end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'lib/pagemaster/site.rb', line 7 def opts @opts end |
Instance Method Details
#config_from_file ⇒ Object
25 26 27 |
# File 'lib/pagemaster/site.rb', line 25 def config_from_file YAML.load_file "#{`pwd`.strip}/_config.yml" end |
#generate_pages ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/pagemaster/site.rb', line 45 def generate_pages paths = @collections.map do |c| c.generate_pages @opts, @collections_dir, @source_dir end.flatten puts Rainbow('Done ✔').green paths end |
#parse_collections ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pagemaster/site.rb', line 31 def parse_collections collections_config = @config.dig 'collections' raise Error::InvalidConfig, "Cannot find 'collections' key in _config.yml" if collections_config.nil? args.map do |a| raise Error::InvalidArgument, "Cannot find requested collection #{a} in _config.yml" unless collections_config.key? a Collection.new(a, collections_config.fetch(a)) end end |