class Jekyll::Waxify::JekyllConfig
JekyllConfig: represents _config.yml in text and yaml
Attributes
jekyll_dir[R]
new_config[R]
text[R]
yaml[R]
Public Class Methods
new(framework_dir, jekyll_dir, new_config = {}, config_file = "_config.yml")
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 12 def initialize(framework_dir, jekyll_dir, new_config = {}, config_file = "_config.yml") @framework_dir = framework_dir @jekyll_dir = jekyll_dir @config_file = config_file @text = File.read("#{@jekyll_dir}/#{@config_file}") @yaml = YAML.safe_load(@text) @new_config = new_config end
Public Instance Methods
add(to_add)
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 30 def add(to_add) @new_config.deep_merge! to_add end
add_collection(coll)
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 49 def add_collection(coll) return unless coll # Make coll images dir and metadata csv file FileUtils.mkdir_p "#{@jekyll_dir}/_data/raw_images/#{coll}" File.open("#{@jekyll_dir}/_data/#{coll}.csv", "w") { |file| file.write("pid,label\n") } @yaml["collections"] ||= {} return if @yaml.dig("collections", coll) # Add coll to new config stanzas add( { "collections" => { coll => { "output" => true, "layout" => "wax_item", "metadata" => { "source" => "#{coll}.csv" }, "images" => { "source" => "raw_images/#{coll}" } } } } ) end
add_cors()
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 34 def add_cors return if @yaml.dig("webrick", "header", "Access-Control-Allow-Origin") # Add CORS stanza to _config.yml add( { "webrick" => { "headers" => { "Access-Control-Allow-Origin" => "*" } } } ) end
deploy_framework()
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 25 def deploy_framework # copy framework documents to jekyll FileUtils.cp_r @framework_dir, @jekyll_dir end
merge()
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 74 def merge @new_config["waxified"] = true new_yaml = @new_config.to_yaml.sub("---\n", "") # collection block is terminated by EOF or a new key, i.e. a line # that begins a character other than whitespace or hash groups = @text.match /(^collections:.*\n.+\n)(\Z|[^\s\#].*)/m if groups.nil? # there are no collections in initial yaml, so append new_yaml @text += new_yaml else # merge collections from @new_config into collections collections = YAML.safe_load(groups[1]) collections.deep_merge! @new_config @text = groups.pre_match + collections.to_yaml.sub("---\n","") + groups[2] end end
save()
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 96 def save File.open(@config_file, "w") { |f| f.puts @text } end
waxified()
click to toggle source
# File lib/jekyll/waxify/jekyll_config.rb, line 21 def waxified @yaml["waxified"] end