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

View file

@ -34,14 +34,24 @@ module Ace
# This class represents the items which will be # This class represents the items which will be
# eventually rendered like concrete posts, tags etc. # eventually rendered like concrete posts, tags etc.
class Item class Item
@@subclasses ||= Array.new
def self.inherited(subclass) def self.inherited(subclass)
@@subclasses << subclass self.subclasses << subclass
end
def self.subclasses
@subclasses ||= Array.new
end end
@@instances ||= Array.new
def self.instances 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 end
def self.before_filters def self.before_filters
@ -111,11 +121,11 @@ module Ace
end end
def save! 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) FileUtils.mkdir_p File.dirname(self.output_path)
File.open(self.output_path, "w") do |file| File.open(self.output_path, "w") do |file|
file.puts content file.puts(content)
end end
end end
end end

View file

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

View file

@ -3,7 +3,10 @@
require "ace/filters" require "ace/filters"
require "template-inheritance" 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 module Ace
class LayoutFilter < Filter 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