lib/ace.rb in ace-0.1 vs lib/ace.rb in ace-0.3
- old
+ new
@@ -7,25 +7,30 @@
# 4) render all the items (here the filters & layouting run)
# 5) match the routes, write the files
require "yaml"
require "fileutils"
+require "ace/filters/sass"
module Ace
+ module Helpers
+ # include your helpers here
+ end
+
class RawItem
attr_accessor :path, :metadata, :content
def initialize(path)
@data = File.read(path)
end
def parse
pieces = @data.split(/^-{3,5}\s*$/)
- if pieces.size < 3
- raise RuntimeError.new(
- "The file '#{content_filename}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format."
- )
- end
+ # if pieces.size < 3
+ # raise RuntimeError.new(
+ # "The file '#{path}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format."
+ # )
+ # end
# Parse
self.metadata = YAML.load(pieces[1]).inject(Hash.new) { |metadata, pair| metadata.merge(pair[0].to_sym => pair[1]) } || Hash.new
self.content = pieces[2..-1].join.strip
end
@@ -34,14 +39,16 @@
# This class represents the items which will be
# eventually rendered like concrete posts, tags etc.
class Item
def self.inherited(subclass)
self.subclasses << subclass
+ subclass.before_filters.push(*self.before_filters)
+ subclass.after_filters.push(*self.after_filters)
end
def self.subclasses
- @subclasses ||= Array.new
+ @subclasses ||= [self]
end
def self.instances
@instances ||= Array.new
end
@@ -109,10 +116,27 @@
self.class.after_filters.inject(output) do |buffer, filter|
filter.call(self, buffer)
end
end
+ def server_path
+ absolute = self.output_path.sub(/^output\//, "")
+ "/#{absolute}"
+ end
+
+ def base_url
+ self.config[:base_url]
+ end
+
+ def permalink
+ if self.config[:base_url].nil?
+ raise "You have to add :base_url into config.yml or redefine #base_url method!"
+ end
+
+ "#{self.base_url}#{self.server_path}"
+ end
+
attr_writer :output_path
def output_path
@output_path ||= begin
unless self.original_path.nil?
self.original_path.sub("content", "output")
@@ -120,21 +144,18 @@
end
end
def save!
content = self.render # so filters can influence output_path
+ puts "~ [RENDER] #{self.output_path}"
FileUtils.mkdir_p File.dirname(self.output_path)
File.open(self.output_path, "w") do |file|
file.puts(content)
end
end
end
class Asset < Item
- end
-
- module Helpers
- def link_to(anchor, path_or_item, options = nil)
- end
+ before Ace::SassFilter
end
end