Class: Amber::SiteConfiguration
- Inherits:
-
Object
- Object
- Amber::SiteConfiguration
- Extended by:
- Forwardable
- Defined in:
- lib/amber/site_configuration.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
an array of SiteConfigurations that are attached as sub-sites to this one.
-
#config_dir ⇒ Object
Returns the value of attribute config_dir.
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#default_locale ⇒ Object
Returns the value of attribute default_locale.
-
#dest_dir ⇒ Object
Returns the value of attribute dest_dir.
-
#layouts_dir ⇒ Object
Returns the value of attribute layouts_dir.
-
#locales ⇒ Object
Returns the value of attribute locales.
-
#locales_dir ⇒ Object
Returns the value of attribute locales_dir.
-
#menu ⇒ Object
Returns the value of attribute menu.
-
#menu_file ⇒ Object
Returns the value of attribute menu_file.
-
#pages_dir ⇒ Object
Returns the value of attribute pages_dir.
-
#pagination_size ⇒ Object
Returns the value of attribute pagination_size.
-
#path ⇒ Object
Sets the attribute path.
-
#path_prefix ⇒ Object
(also: #path)
Returns the value of attribute path_prefix.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
-
#short_paths ⇒ Object
Returns the value of attribute short_paths.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.load(site, root_dir, options = {}) ⇒ Object
CLASS METHODS.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #config_path(file) ⇒ Object
-
#eval ⇒ Object
def pages_changed? self.changed? || @children.detect {|child| child.changed?} end.
- #find_in_directory_tree(target_dir_name, target_file_name, directory_tree = nil) ⇒ Object
-
#initialize(site, root_dir, options = {}) ⇒ SiteConfiguration
constructor
accepts a file_path to a configuration file.
-
#map(path_to_directory_source, options = {}) ⇒ Object
map(‘/path’ => ‘../othersite’).
- #reset_timestamp ⇒ Object
Constructor Details
#initialize(site, root_dir, options = {}) ⇒ SiteConfiguration
accepts a file_path to a configuration file.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/amber/site_configuration.rb', line 57 def initialize(site, root_dir, ={}) @children = [] @path_prefix = nil @site = site @root_dir = File.(find_in_directory_tree('amber', 'config.rb', root_dir)) if @root_dir == '/' puts "Could not find amber/config.rb in the directory tree. Run `amber` from inside an amber website directory" exit(1) end @pages_dir = File.join(@root_dir, 'pages') @dest_dir = File.join(@root_dir, 'public') @config_dir = File.join(@root_dir, 'amber') @config_file = config_path('config.rb') @menu_file = config_path('menu.txt') @locales_dir = config_path('locales') @layouts_dir = config_path('layouts') @title = "untitled" @pagination_size = 20 @menu = Menu.new('root') @menu.load(@menu_file) if @menu_file self.eval @path_prefix = [:path_prefix] if [:path_prefix] self.cleanup Render::Layout.load(@layouts_dir) end |
Instance Attribute Details
#children ⇒ Object
an array of SiteConfigurations that are attached as sub-sites to this one.
36 37 38 |
# File 'lib/amber/site_configuration.rb', line 36 def children @children end |
#config_dir ⇒ Object
Returns the value of attribute config_dir.
26 27 28 |
# File 'lib/amber/site_configuration.rb', line 26 def config_dir @config_dir end |
#config_file ⇒ Object
Returns the value of attribute config_file.
27 28 29 |
# File 'lib/amber/site_configuration.rb', line 27 def config_file @config_file end |
#default_locale ⇒ Object
Returns the value of attribute default_locale.
16 17 18 |
# File 'lib/amber/site_configuration.rb', line 16 def default_locale @default_locale end |
#dest_dir ⇒ Object
Returns the value of attribute dest_dir.
25 26 27 |
# File 'lib/amber/site_configuration.rb', line 25 def dest_dir @dest_dir end |
#layouts_dir ⇒ Object
Returns the value of attribute layouts_dir.
28 29 30 |
# File 'lib/amber/site_configuration.rb', line 28 def layouts_dir @layouts_dir end |
#locales ⇒ Object
Returns the value of attribute locales.
15 16 17 |
# File 'lib/amber/site_configuration.rb', line 15 def locales @locales end |
#locales_dir ⇒ Object
Returns the value of attribute locales_dir.
31 32 33 |
# File 'lib/amber/site_configuration.rb', line 31 def locales_dir @locales_dir end |
#menu ⇒ Object
Returns the value of attribute menu.
21 22 23 |
# File 'lib/amber/site_configuration.rb', line 21 def @menu end |
#menu_file ⇒ Object
Returns the value of attribute menu_file.
30 31 32 |
# File 'lib/amber/site_configuration.rb', line 30 def @menu_file end |
#pages_dir ⇒ Object
Returns the value of attribute pages_dir.
24 25 26 |
# File 'lib/amber/site_configuration.rb', line 24 def pages_dir @pages_dir end |
#pagination_size ⇒ Object
Returns the value of attribute pagination_size.
14 15 16 |
# File 'lib/amber/site_configuration.rb', line 14 def pagination_size @pagination_size end |
#path=(value) ⇒ Object
Sets the attribute path
29 30 31 |
# File 'lib/amber/site_configuration.rb', line 29 def path=(value) @path = value end |
#path_prefix ⇒ Object Also known as: path
Returns the value of attribute path_prefix.
17 18 19 |
# File 'lib/amber/site_configuration.rb', line 17 def path_prefix @path_prefix end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
23 24 25 |
# File 'lib/amber/site_configuration.rb', line 23 def root_dir @root_dir end |
#short_paths ⇒ Object
Returns the value of attribute short_paths.
19 20 21 |
# File 'lib/amber/site_configuration.rb', line 19 def short_paths @short_paths end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
32 33 34 |
# File 'lib/amber/site_configuration.rb', line 32 def @timestamp end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/amber/site_configuration.rb', line 13 def title @title end |
Class Method Details
.load(site, root_dir, options = {}) ⇒ Object
CLASS METHODS
46 47 48 |
# File 'lib/amber/site_configuration.rb', line 46 def self.load(site, root_dir, ={}) SiteConfiguration.new(site, root_dir, ) end |
Instance Method Details
#cleanup ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/amber/site_configuration.rb', line 96 def cleanup @locale ||= I18n.default_locale I18n.default_locale = @locale @locales ||= [@locale] @locales.map! {|locale| if Amber::POSSIBLE_LANGUAGE_CODES.include?(locale.to_s) locale.to_sym else nil end }.compact if @path_prefix @path_prefix.gsub!(%r{^/|/$}, '') @path_prefix = nil if @path_prefix == '' end end |
#config_path(file) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/amber/site_configuration.rb', line 121 def config_path(file) path = File.join(@config_dir, file) if File.exist?(path) path else nil end end |
#eval ⇒ Object
def pages_changed?
self.changed? || @children.detect {|child| child.changed?}
end
117 118 119 |
# File 'lib/amber/site_configuration.rb', line 117 def eval self.instance_eval(File.read(@config_file), @config_file) end |
#find_in_directory_tree(target_dir_name, target_file_name, directory_tree = nil) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/amber/site_configuration.rb', line 134 def find_in_directory_tree(target_dir_name, target_file_name, directory_tree=nil) search_dir = directory_tree || Dir.pwd while search_dir != "/" Dir.foreach(search_dir) do |f| if f == target_dir_name && File.exist?(File.join(search_dir, f,target_file_name)) return search_dir end end search_dir = File.dirname(search_dir) end return search_dir end |
#map(path_to_directory_source, options = {}) ⇒ Object
map(‘/path’ => ‘../othersite’)
90 91 92 93 94 |
# File 'lib/amber/site_configuration.rb', line 90 def map(path_to_directory_source, ={}) path, root_dir = path_to_directory_source.to_a.first config = self.load(@site, root_dir, {:path_prefix => path}) @site.add_config(config) end |
#reset_timestamp ⇒ Object
130 131 132 |
# File 'lib/amber/site_configuration.rb', line 130 def @timestamp = File.mtime(@pages_dir) end |