Class: Howl::Site

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Site

Returns a new instance of Site.



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

def initialize(root)
  @root = Pathname.new(root)
  load_config
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



3
4
5
# File 'lib/howl/site.rb', line 3

def root
  @root
end

#viewObject

Returns the value of attribute view.



3
4
5
# File 'lib/howl/site.rb', line 3

def view
  @view
end

Instance Method Details

#output_path(path = '') ⇒ Object



26
27
28
# File 'lib/howl/site.rb', line 26

def output_path(path = '')
  root + "generated" + path
end

#pagesObject



30
31
32
# File 'lib/howl/site.rb', line 30

def pages
  @pages ||= Dir[pages_path "**/*.*"].map { |path| Page.new(path, self) }
end

#pages_path(path = '') ⇒ Object



22
23
24
# File 'lib/howl/site.rb', line 22

def pages_path(path = '')
  root + "site" + path
end

#path(path) ⇒ Object



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

def path(path)
  root + path
end

#postsObject



34
35
36
# File 'lib/howl/site.rb', line 34

def posts
  @posts ||= Dir[posts_path "**/*.*"].map { |path| Post.new(path, self) }.sort
end

#posts_path(path = '') ⇒ Object



14
15
16
# File 'lib/howl/site.rb', line 14

def posts_path(path = '')
  root + "posts" + path
end

#templatesObject



38
39
40
41
42
43
# File 'lib/howl/site.rb', line 38

def templates
  @templates ||= Hash[Dir[templates_path('*')].map { |path| 
    [Pathname.new(path).relative_path_from(path "templates").to_s, 
     Template.new(path, self)] 
  }]
end

#templates_path(path = '') ⇒ Object



18
19
20
# File 'lib/howl/site.rb', line 18

def templates_path(path = '')
  root + "templates" + path
end

#write_to_diskObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/howl/site.rb', line 45

def write_to_disk
  FileUtils.rm_r(output_path) if File.exist?(output_path)
  (pages + posts).each do |page|
    FileUtils.makedirs(page.output_path.dirname)

    if page.path.binary?
      FileUtils.copy(page.path, page.output_path)
    else
      page.output_path.open("w") do |fh|
        fh.write page.render
      end
    end
  end
end