class Ruhoh::Config
Public Class Methods
new(ruhoh)
click to toggle source
Calls superclass method
# File lib/ruhoh/config.rb, line 5 def initialize(ruhoh) @ruhoh = ruhoh @data = {} super(@data) end
Public Instance Methods
base_path()
click to toggle source
# File lib/ruhoh/config.rb, line 29 def base_path return '/' unless (@ruhoh.env == 'production') @data['base_path'] += "/" unless @data['base_path'][-1] == '/' string = @data['base_path'].chomp('/').reverse.chomp('/').reverse return '/' if string.empty? || string == '/' "/#{ string }/" end
touch()
click to toggle source
Regenerate the config data
# File lib/ruhoh/config.rb, line 12 def touch data = @ruhoh.cascade.merge_data_file('config') || {} data = Ruhoh::Utils.deep_merge(data, collections_config) data = Ruhoh::Utils.deep_merge(data, find_theme_path) @data.clear @data.merge!(data) Time.default_format = @data['date_format'] @data["compiled_path"] = File.expand_path(@data["compiled_path"]) changed notify_observers(@data) self end
Private Instance Methods
collections_config()
click to toggle source
Quick and dirty way to scan for config files in collection folders. This is needed because we don’t know which collection defines itself as a theme so we’ll scan for any configs and merge the data to find the theme folder.
# File lib/ruhoh/config.rb, line 53 def collections_config data = {} @ruhoh.cascade.paths.map{ |a| a['path'] }.each do |path| FileUtils.cd(path) { Dir["*/config.*"].each { |id| next unless File.exist?(id) && FileTest.file?(id) data = Ruhoh::Utils.deep_merge(data, (Ruhoh::Parse.data_file(File.realpath(id)) || {})) } } end data end
find_theme_path()
click to toggle source
# File lib/ruhoh/config.rb, line 40 def find_theme_path theme_name = @data.find { |resource, data| data.is_a?(Hash) && data['use'] == "theme" } if theme_name Ruhoh::Friend.say { plain "Using theme: \"#{theme_name[0]}\""} { "_theme_collection" => theme_name[0] } else { "_theme_collection" => nil } end end