Ace is now +/- stable.

This commit is contained in:
Jakub Šťastný aka Botanicus 2011-02-17 05:40:09 +00:00
parent 4cc4e303ab
commit 8a32698a53
5 changed files with 49 additions and 10 deletions

View file

@ -53,7 +53,7 @@ end
puts
rules.generators.each do |generator_klass|
puts "Running #{generator_klass}"
puts "~ Running #{generator_klass}"
generator = generator_klass.new
begin
if generator.respond_to?(:run)
@ -70,7 +70,7 @@ end
puts
Ace::Item.instances.each do |item|
puts "Generating #{item.output_path}"
Ace::Item.all_instances.each do |item|
puts "~ Generating #{item.output_path}"
item.save!
end

View file

@ -34,14 +34,24 @@ module Ace
# This class represents the items which will be
# eventually rendered like concrete posts, tags etc.
class Item
@@subclasses ||= Array.new
def self.inherited(subclass)
@@subclasses << subclass
self.subclasses << subclass
end
def self.subclasses
@subclasses ||= Array.new
end
@@instances ||= Array.new
def self.instances
@@instances
@instances ||= Array.new
end
def self.all_subclasses
self.subclasses + self.subclasses.map(&:subclasses).flatten
end
def self.all_instances
self.all_subclasses.map(&:instances).flatten
end
def self.before_filters
@ -111,11 +121,11 @@ module Ace
end
def save!
content = self.render.chomp # so filters can influence output_path
content = self.render # so filters can influence output_path
FileUtils.mkdir_p File.dirname(self.output_path)
File.open(self.output_path, "w") do |file|
file.puts content
file.puts(content)
end
end
end

View file

@ -3,6 +3,7 @@
require "haml"
require "ace/filters"
# This is just a plain Haml, no template inheritance.
module Ace
class HamlFilter < Filter
# http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml/Engine.html

View file

@ -3,7 +3,10 @@
require "ace/filters"
require "template-inheritance"
TemplateInheritance::Template.paths << File.join(Dir.pwd, "layouts")
layouts = File.join(Dir.pwd, "layouts")
unless TemplateInheritance::Template.paths.include?(layouts)
TemplateInheritance::Template.paths.unshift(layouts)
end
module Ace
class LayoutFilter < Filter

View file

@ -0,0 +1,25 @@
# encoding: utf-8
require "ace/filters"
require "template-inheritance"
layouts = File.join(Dir.pwd, "layouts")
unless TemplateInheritance::Template.paths.include?(layouts)
TemplateInheritance::Template.paths.unshift(layouts)
end
TemplateInheritance::Template.paths << File.join(Dir.pwd, "content")
module Ace
class TemplateFilter < Filter
def call(item, content)
if item.output_path
item.output_path = item.output_path.split(".")[0..-2].join(".")
end
relative_path = item.original_path.sub("content/", "")
template = TemplateInheritance::Template.new(relative_path)
return template.render(item: item)
end
end
end