Class: Awestruct::Site

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/awestruct/site.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Site) initialize(config)

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

- (Object) dir (readonly)

Returns the value of attribute dir



6
7
8
# File 'lib/awestruct/site.rb', line 6

def dir
  @dir
end

- (Object) layouts (readonly)

Returns the value of attribute layouts



10
11
12
# File 'lib/awestruct/site.rb', line 10

def layouts
  @layouts
end

- (Object) output_dir (readonly)

Returns the value of attribute output_dir



7
8
9
# File 'lib/awestruct/site.rb', line 7

def output_dir
  @output_dir
end

- (Object) pages

Returns the value of attribute pages



11
12
13
# File 'lib/awestruct/site.rb', line 11

def pages
  @pages
end

- (Object) tmp_dir (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

- (Object) apply_plugins



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

- (Boolean) has_page?(path)

Returns:

  • (Boolean)


27
28
29
# File 'lib/awestruct/site.rb', line 27

def has_page?(path)
  ! pages.find{|e| e.source_path == path}.nil?
end

- (Object) output_path(path, ext = nil)



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

- (Object) url_path(path, ext = nil)



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