Class: JekyllBookshop::Opener
- Inherits:
-
Object
- Object
- JekyllBookshop::Opener
- Defined in:
- lib/jekyll-bookshop/opener.rb
Class Method Summary collapse
- .apply_array(hash, key, arr) ⇒ Object
- .bookshop_component_locations(locations) ⇒ Object
- .bookshop_shared_locations(locations) ⇒ Object
- .filter_bookshops(src, locations) ⇒ Object
-
.open_bookshop(site) ⇒ Object
Add the paths to find bookshop(s).
Class Method Details
.apply_array(hash, key, arr) ⇒ Object
44 45 46 47 |
# File 'lib/jekyll-bookshop/opener.rb', line 44 def self.apply_array(hash, key, arr) hash[key] ||= [] hash[key].push(*arr) end |
.bookshop_component_locations(locations) ⇒ Object
32 33 34 35 36 |
# File 'lib/jekyll-bookshop/opener.rb', line 32 def self.bookshop_component_locations(locations) locations&.collect do |location| Pathname.new("#{location}/components/").cleanpath.to_s end end |
.bookshop_shared_locations(locations) ⇒ Object
38 39 40 41 42 |
# File 'lib/jekyll-bookshop/opener.rb', line 38 def self.bookshop_shared_locations(locations) locations&.collect do |location| Pathname.new("#{location}/shared/jekyll/").cleanpath.to_s end end |
.filter_bookshops(src, locations) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/jekyll-bookshop/opener.rb', line 23 def self.filter_bookshops(src, locations) mapped_locations = locations&.collect do |location| Pathname.new("#{src}/#{location}/").cleanpath.to_s end mapped_locations.select do |location| Dir.exist?(location) end end |
.open_bookshop(site) ⇒ Object
Add the paths to find bookshop(s)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/jekyll-bookshop/opener.rb', line 6 def self.open_bookshop(site) return unless site.config["bookshop_locations"] bookshop_base_locations = filter_bookshops(site.source, site.config["bookshop_locations"]) bookshop_component_locations = bookshop_component_locations(bookshop_base_locations) bookshop_shared_locations = bookshop_shared_locations(bookshop_base_locations) site.config["sass"] ||= {} apply_array(site.config["sass"], "load_paths", bookshop_base_locations) # Paired with CloudCannon/jekyll-watch apply_array(site.config, "watch_dirs", bookshop_base_locations) apply_array(site.config, "bookshop_base_locations", bookshop_base_locations) apply_array(site.config, "bookshop_component_locations", bookshop_component_locations) apply_array(site.config, "bookshop_shared_locations", bookshop_shared_locations) end |