Class: Potion::Site

Inherits:
Object
  • Object
show all
Includes:
Potion, Deployers
Defined in:
lib/potion/site.rb

Constant Summary collapse

@@extensions =
[]

Constants included from Potion

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Deployers

#deploy_to_gh_pages

Constructor Details

#initialize(base_path, destination_path, fast_build = false) ⇒ Site

Returns a new instance of Site.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/potion/site.rb', line 20

def initialize(base_path, destination_path, fast_build = false)
  @base_path  = base_path
  @destination_path = destination_path
  @fast_build = fast_build
  
  @config     = load_config
  @metadata   = {}
  
  @files        = find_all_files
  
  load_extensions
  
  @layouts      = find_layouts
  @posts        = find_posts
  @pages        = find_pages
  @static_files = find_static_files
end

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



4
5
6
# File 'lib/potion/site.rb', line 4

def base_path
  @base_path
end

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/potion/site.rb', line 4

def config
  @config
end

#destination_pathObject

Returns the value of attribute destination_path.



4
5
6
# File 'lib/potion/site.rb', line 4

def destination_path
  @destination_path
end

#fast_buildObject

Returns the value of attribute fast_build.



4
5
6
# File 'lib/potion/site.rb', line 4

def fast_build
  @fast_build
end

#filesObject

Returns the value of attribute files.



4
5
6
# File 'lib/potion/site.rb', line 4

def files
  @files
end

#layoutsObject

Returns the value of attribute layouts.



4
5
6
# File 'lib/potion/site.rb', line 4

def layouts
  @layouts
end

#metadataObject

Returns the value of attribute metadata.



4
5
6
# File 'lib/potion/site.rb', line 4

def 
  @metadata
end

#pagesObject

Returns the value of attribute pages.



4
5
6
# File 'lib/potion/site.rb', line 4

def pages
  @pages
end

#postsObject

Returns the value of attribute posts.



4
5
6
# File 'lib/potion/site.rb', line 4

def posts
  @posts
end

#static_filesObject

Returns the value of attribute static_files.



4
5
6
# File 'lib/potion/site.rb', line 4

def static_files
  @static_files
end

Class Method Details

.extensionsObject



16
17
18
# File 'lib/potion/site.rb', line 16

def self.extensions
  @@extensions
end

.register_extension(klass) ⇒ Object



8
9
10
# File 'lib/potion/site.rb', line 8

def self.register_extension(klass)
  @@extensions << klass
end

.remove_extension(klass) ⇒ Object



12
13
14
# File 'lib/potion/site.rb', line 12

def self.remove_extension(klass)
  @@extensions = @@extensions - [klass]
end

Instance Method Details

#deploy_to(target) ⇒ Object



101
102
103
# File 'lib/potion/site.rb', line 101

def deploy_to(target)
  self.send("deploy_to_#{target}", @destination_path)
end

#find_all_filesObject



46
47
48
49
# File 'lib/potion/site.rb', line 46

def find_all_files
  Dir[@base_path + "/**/*"].reject {|x| File.directory?(x)}
  
end

#find_layout_by_name(name) ⇒ Object



65
66
67
# File 'lib/potion/site.rb', line 65

def find_layout_by_name(name)
  @layouts.select {|layout| layout.name == name}.first
end

#find_layoutsObject



58
59
60
61
62
63
# File 'lib/potion/site.rb', line 58

def find_layouts
  layouts = @files.select {|path| path.include? "_layouts"}
  layouts.map do |layout|
    Layout.new(layout, self)
  end
end

#find_pagesObject



77
78
79
80
81
82
83
# File 'lib/potion/site.rb', line 77

def find_pages
  pages = @files.reject {|path| path.include?("/_")}
  pages = (pages)
  pages.map do |page| 
    Page.new(page, self)
  end
end

#find_postsObject



69
70
71
72
73
74
75
# File 'lib/potion/site.rb', line 69

def find_posts
  posts = @files.select {|path| path.include?("_posts")}
  posts = (posts)
  posts.map  do |post| 
    Post.new(post, self)
  end
end

#find_static_filesObject



85
86
87
88
89
90
91
# File 'lib/potion/site.rb', line 85

def find_static_files
  static_files = @files.reject {|path| path.include?("/_")}
  static_files = static_files - (static_files)
  static_files.map do |static_file|
    StaticFile.new(static_file, self)
  end
end

#load_configObject



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

def load_config
  config_path = File.join(@base_path, "_config.yaml")
  raise "No config file found at '#{config_path}'" unless File.exists?(config_path)
  config = YAML.load(File.open(config_path))
  return {} if config == false
  config
end

#load_extensionsObject



51
52
53
54
55
56
# File 'lib/potion/site.rb', line 51

def load_extensions
  site_extensions = @files.select {|path| path.include?("_extensions") && File.extname(path) == ".rb" }
  site_extensions.each do |extension|
    require extension
  end
end

#writeObject



93
94
95
96
97
98
99
# File 'lib/potion/site.rb', line 93

def write
  puts "*** Building...\n"
  
  (@posts + @pages + @static_files).each do |item|
    item.write
  end
end