lib/deface/dsl/loader.rb in deface-1.0.0.rc2 vs lib/deface/dsl/loader.rb in deface-1.0.0.rc3

- old
+ new

@@ -4,12 +4,12 @@ module Deface module DSL class Loader def self.load(filename, options = nil, &block) - unless File.basename(filename) =~ /^[^\.]+(.html.(erb|haml)){0,1}.deface$/ - raise "Deface::DSL does not know how to read '#{filename}'. Override files should end with just .deface, .html.erb.deface, or .html.haml.deface" + unless File.basename(filename) =~ /^[^\.]+(.html.(erb|haml|slim)){0,1}.deface$/ + raise "Deface::DSL does not know how to read '#{filename}'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface" end unless file_in_dir_below_overrides?(filename) raise "Deface::DSL overrides must be in a sub-directory that matches the views virtual path. Move '#{filename}' into a sub-directory." end @@ -35,10 +35,19 @@ context = Context.new(context_name) context.virtual_path(determine_virtual_path(filename)) context.instance_eval(dsl_commands) context.haml(the_rest) context.create_override + elsif context_name.end_with?('.html.slim') + dsl_commands, the_rest = extract_dsl_commands_from_slim(file_contents) + + context_name = context_name.gsub('.html.slim', '') + context = Context.new(context_name) + context.virtual_path(determine_virtual_path(filename)) + context.instance_eval(dsl_commands) + context.slim(the_rest) + context.create_override else context = Context.new(context_name) context.virtual_path(determine_virtual_path(filename)) context.instance_eval(file_contents) context.create_override @@ -97,12 +106,17 @@ end [dsl_commands, file_contents] end - private + class << self + alias_method :extract_dsl_commands_from_slim, :extract_dsl_commands_from_haml + end + + private + def self.starts_with_html_comment?(line) line.lstrip.index('<!--') == 0 end def self.starts_with_haml_comment?(line) @@ -124,6 +138,6 @@ end result end end end -end +end \ No newline at end of file