Class: Potion::Site
- Inherits:
-
Object
- Object
- Potion::Site
- Defined in:
- lib/potion/site.rb
Constant Summary collapse
- @@extensions =
[]
Constants included from Potion
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#config ⇒ Object
Returns the value of attribute config.
-
#destination_path ⇒ Object
Returns the value of attribute destination_path.
-
#fast_build ⇒ Object
Returns the value of attribute fast_build.
-
#files ⇒ Object
Returns the value of attribute files.
-
#layouts ⇒ Object
Returns the value of attribute layouts.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#posts ⇒ Object
Returns the value of attribute posts.
-
#static_files ⇒ Object
Returns the value of attribute static_files.
Class Method Summary collapse
Instance Method Summary collapse
- #deploy_to(target) ⇒ Object
- #find_all_files ⇒ Object
- #find_layout_by_name(name) ⇒ Object
- #find_layouts ⇒ Object
- #find_pages ⇒ Object
- #find_posts ⇒ Object
- #find_static_files ⇒ Object
-
#initialize(base_path, destination_path, fast_build = false) ⇒ Site
constructor
A new instance of Site.
- #load_config ⇒ Object
- #load_extensions ⇒ Object
- #write ⇒ Object
Methods included from Deployers
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_path ⇒ Object
Returns the value of attribute base_path.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def base_path @base_path end |
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def config @config end |
#destination_path ⇒ Object
Returns the value of attribute destination_path.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def destination_path @destination_path end |
#fast_build ⇒ Object
Returns the value of attribute fast_build.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def fast_build @fast_build end |
#files ⇒ Object
Returns the value of attribute files.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def files @files end |
#layouts ⇒ Object
Returns the value of attribute layouts.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def layouts @layouts end |
#metadata ⇒ Object
Returns the value of attribute metadata.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def @metadata end |
#pages ⇒ Object
Returns the value of attribute pages.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def pages @pages end |
#posts ⇒ Object
Returns the value of attribute posts.
4 5 6 |
# File 'lib/potion/site.rb', line 4 def posts @posts end |
#static_files ⇒ Object
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
.extensions ⇒ Object
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_files ⇒ Object
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_layouts ⇒ Object
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_pages ⇒ Object
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_posts ⇒ Object
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_files ⇒ Object
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_config ⇒ Object
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_extensions ⇒ Object
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 |
#write ⇒ Object
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 |