Class: Broadway::Configuration
- Inherits:
-
Object
- Object
- Broadway::Configuration
- Defined in:
- lib/broadway/resources/configuration.rb
Constant Summary collapse
- DEFAULTS =
Default options. Overriden by values in _settings.yml or command-line opts. (Strings rather symbols used for compatability with YAML)
{ :auto => false, :server => false, :server_port => 4000, :source => ".", :settings => "_config.yml", :destination => "_site", :lsi => false, :pygments => false, :markdown => "rdiscount", :permalink => "pretty", :url_type => "relative", :url => "http://localhost:4567", :locales => "locales", :language => "en-US", :maruku => { :use_tex => false, :use_divs => false, :png_engine => "blahtex", :png_dir => "images/latex", :png_url => "/images/latex" }, :layouts => "_layouts", :posts_include => [".textile", ".markdown"], :theme_path => "themes", :theme_versions => ["main"] }
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(site, overrides) ⇒ Configuration
constructor
A new instance of Configuration.
- #merge(overrides) ⇒ Object
- #merge_extra_settings!(settings) ⇒ Object
- #read(overrides) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(site, overrides) ⇒ Configuration
Returns a new instance of Configuration.
39 40 41 42 |
# File 'lib/broadway/resources/configuration.rb', line 39 def initialize(site, overrides) self.site = site self.settings = merge(overrides) end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
3 4 5 |
# File 'lib/broadway/resources/configuration.rb', line 3 def settings @settings end |
#site ⇒ Object
Returns the value of attribute site.
3 4 5 |
# File 'lib/broadway/resources/configuration.rb', line 3 def site @site end |
Instance Method Details
#get(path) ⇒ Object
48 49 50 51 52 |
# File 'lib/broadway/resources/configuration.rb', line 48 def get(path) result = settings path.to_s.split(".").each { |node| result = result[node.to_sym] if result } result.nil? ? "" : result end |
#merge(overrides) ⇒ Object
44 45 46 |
# File 'lib/broadway/resources/configuration.rb', line 44 def merge(overrides) DEFAULTS.deep_merge(read(overrides)).merge(overrides) end |
#merge_extra_settings!(settings) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/broadway/resources/configuration.rb', line 76 def merge_extra_settings!(settings) locale = ::File.join(settings[:locales], "#{settings[:language]}.yml") settings.merge!(YAML.load_file(locale)) if ::File.exists?(locale) settings_dir = ::File.join(settings[:source], "settings") return unless ::File.exists?(settings_dir) Dir.glob("#{settings_dir}/**/*").each do |file| next if ::File.directory?(file) path = file.gsub(/settings\//, "").split(".")[0..-2].join("") ext = ::File.extname(file) if ext =~ /yml/ data = YAML.load_file(file) elsif ext =~ /xml/ data = parse_children Nokogiri::XML(IO.read(file)).children[0] else data = IO.read(file) end next unless data name = path.split("/").first if path =~ /\// settings[name] ||= {} target = settings[name] name = path.split("/").last else target = settings end if target.has_key?(name) target[name].merge!(data) else target[name] = data end end end |
#read(overrides) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/broadway/resources/configuration.rb', line 54 def read(overrides) overrides = overrides.recursively_symbolize_keys! # _settings.yml may override default source location, but until # then, we need to know where to look for _settings.yml source = overrides[:source] || DEFAULTS[:source] settings_file = overrides[:settings] || DEFAULTS[:settings] settings_file = ::File.join(source, settings_file) unless ::File.exists?(settings_file) # Get configuration from <source>/_config.yml begin settings = YAML.load_file(settings_file).recursively_symbolize_keys! raise "Invalid configuration - #{settings_file}" if !settings.is_a?(Hash) #$stdout.puts "Configuration from #{settings_file}" rescue => err puts err.inspect #$stderr.puts "WARNING: Could not read configuration. Using defaults (and options)." #$stderr.puts "\t" + err.to_s settings = {} end settings end |
#setup ⇒ Object
111 112 |
# File 'lib/broadway/resources/configuration.rb', line 111 def setup end |