class Potion::Site
Attributes
base_path[RW]
config[RW]
destination_path[RW]
fast_build[RW]
files[RW]
layouts[RW]
metadata[RW]
pages[RW]
posts[RW]
static_files[RW]
Public Class Methods
extensions()
click to toggle source
# File lib/potion/site.rb, line 16 def self.extensions @@extensions end
new(base_path, destination_path, fast_build = false)
click to toggle source
# 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
register_extension(klass)
click to toggle source
# File lib/potion/site.rb, line 8 def self.register_extension(klass) @@extensions << klass end
remove_extension(klass)
click to toggle source
# File lib/potion/site.rb, line 12 def self.remove_extension(klass) @@extensions = @@extensions - [klass] end
Public Instance Methods
deploy_to(target)
click to toggle source
# File lib/potion/site.rb, line 101 def deploy_to(target) self.send("deploy_to_#{target}", @destination_path) end
find_all_files()
click to toggle source
# 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)
click to toggle source
# File lib/potion/site.rb, line 65 def find_layout_by_name(name) @layouts.select {|layout| layout.name == name}.first end
find_layouts()
click to toggle source
# 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()
click to toggle source
# File lib/potion/site.rb, line 77 def find_pages pages = @files.reject {|path| path.include?("/_")} pages = filter_for_yaml_metadata(pages) pages.map do |page| Page.new(page, self) end end
find_posts()
click to toggle source
# File lib/potion/site.rb, line 69 def find_posts posts = @files.select {|path| path.include?("_posts")} posts = filter_for_yaml_metadata(posts) posts.map do |post| Post.new(post, self) end end
find_static_files()
click to toggle source
# File lib/potion/site.rb, line 85 def find_static_files static_files = @files.reject {|path| path.include?("/_")} static_files = static_files - filter_for_yaml_metadata(static_files) static_files.map do |static_file| StaticFile.new(static_file, self) end end
load_config()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/potion/site.rb, line 93 def write puts "*** Building...\n" (@posts + @pages + @static_files).each do |item| item.write end end
Private Instance Methods
filter_for_yaml_metadata(files)
click to toggle source
# File lib/potion/site.rb, line 107 def filter_for_yaml_metadata(files) files.select do |file| prefix = File.open(file) {|stream| stream.read(3)} prefix == "---" end end