Class: Awestruct::Site
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Awestruct::Site
- Defined in:
- lib/awestruct/site.rb
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#tmp_dir ⇒ Object
readonly
Returns the value of attribute tmp_dir.
Instance Method Summary collapse
- #apply_plugins ⇒ Object
- #has_page?(path) ⇒ Boolean
-
#initialize(config) ⇒ Site
constructor
A new instance of Site.
- #output_path(path, ext = nil) ⇒ Object
- #url_path(path, ext = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Site
Returns a new instance of Site.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/awestruct/site.rb', line 13 def initialize(config) super({}) @dir = config.input_dir @output_dir = config.output_dir @tmp_dir = config.tmp_dir FileUtils.mkdir_p( @output_dir ) FileUtils.mkdir_p( @tmp_dir ) @pages = [] @layouts = {} end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/awestruct/site.rb', line 6 def dir @dir end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
10 11 12 |
# File 'lib/awestruct/site.rb', line 10 def layouts @layouts end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
7 8 9 |
# File 'lib/awestruct/site.rb', line 7 def output_dir @output_dir end |
#pages ⇒ Object
Returns the value of attribute pages.
11 12 13 |
# File 'lib/awestruct/site.rb', line 11 def pages @pages end |
#tmp_dir ⇒ Object (readonly)
Returns the value of attribute tmp_dir.
8 9 10 |
# File 'lib/awestruct/site.rb', line 8 def tmp_dir @tmp_dir end |
Instance Method Details
#apply_plugins ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/awestruct/site.rb', line 43 def apply_plugins Dir[ File.join( @dir, '_plugins', '*.rb' ) ].each do |rb_path| site_root = @dir output_root = @output_dir begin eval File.read( rb_path ) rescue => e puts e puts e.backtrace end end end |
#has_page?(path) ⇒ Boolean
27 28 29 |
# File 'lib/awestruct/site.rb', line 27 def has_page?(path) ! pages.find{|e| e.path == path}.nil? end |
#output_path(path, ext = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/awestruct/site.rb', line 31 def output_path(path, ext=nil) path = File.join( @output_dir, path[ @dir.size..-1] ) unless ( ext.nil? ) path = File.join( File.dirname( path ), File.basename( path, ext ) ) end path end |
#url_path(path, ext = nil) ⇒ Object
39 40 41 |
# File 'lib/awestruct/site.rb', line 39 def url_path(path, ext=nil) url_path = output_path( path, ext )[ @output_dir.size .. -1 ] end |