lib/masterview/template_spec.rb in masterview-0.3.2 vs lib/masterview/template_spec.rb in masterview-0.3.3
- old
+ new
@@ -10,19 +10,19 @@
OK = 'OK'
ImportsOutdated = 'Imports(s) outdated'
Conflicts = 'Conflict(s)'
InvalidXHTML = 'Invalid XHTML'
end
-
+
def initialize(path = nil)
@path = path
@status = ''
@message = ''
@gen_parts = []
@build_list = []
end
-
+
# get short base name of path
def basename
File.basename @path
end
@@ -67,11 +67,11 @@
# create a template_spec
def self.scan_template(template, path, content_hash = {})
template_spec = TemplateSpec.new(path)
listener = MasterView::Analyzer::Listener.new( :template_pathname => Pathname.for_path(path) )
- begin
+ begin
MasterView::Parser.parse( template, :rescue_exceptions => false, :listeners => [listener])
template_spec.build_list = listener.list
conflicts = content_hash.keys & listener.content.keys
content_hash.merge! listener.content
if conflicts.empty?
@@ -103,11 +103,11 @@
invalid_with_dups = invalid_list_items.collect { |li| li.name }
invalid = invalid_with_dups.uniq.sort
invalid
end
- # rebuild template updating all imports, returns the string contents,
+ # rebuild template updating all imports, returns the string contents,
# if options[:write_to_file] = true then it will write the contents to file if different and return true, if identical then returns false
# otherwise this method returns the content of the template
# raise error for any other problems. options[:backup] = true to make backup before rebuilding, uses MasterView::IOMgr.backup to determine
# path for where to store backup files. If MasterView::IOMgr.backup is nil, then no backup is created.
def rebuild_template(content_hash, options = {} )
@@ -146,10 +146,28 @@
backup_path = self.path+'.'+Time.new.to_i.to_s
Log.debug { 'creating backup file '+backup_path }
IOMgr.backup.path(backup_path).write(contents_to_backup)
end
+ # remove file
+ def remove_rhtml(options={})
+ removed = []
+ self.gen_parts.each do |gen_rhtml|
+ mio = IOMgr.erb.path(gen_rhtml)
+ if mio.exist?
+ mio.remove
+ removed << gen_rhtml
+ end
+ end
+ removed
+ end
+
+ # file exist?
+ def file_exist?
+ IOMgr.template.path(self.path).exist?
+ end
+
# create empty shell file consisting of layout and a comment for where to insert new content, return contents
def self.create_empty_shell(template_spec_to_copy, content_hash, content_to_insert, options = {} )
from_spec = template_spec_to_copy
content_hash['empty_shell_contents'] = []
content_hash['empty_shell_contents'] << MasterView::Analyzer::ContentEntry.new(content_to_insert)
@@ -166,25 +184,25 @@
end
class CreateShellERBValues
attr_reader :controller_name, :action_name, :controller_file_name, :controller_view_dir_name
def initialize(controller_name, action_name)
- @controller_name = Inflector.underscore(Inflector.singularize(controller_name))
- @action_name = Inflector.underscore(Inflector.singularize(action_name))
- @controller_file_name = @controller_name
+ @controller_name = Inflector.underscore(Inflector.singularize(controller_name))
+ @action_name = Inflector.underscore(Inflector.singularize(action_name))
+ @controller_file_name = @controller_name
@controller_view_dir_name = @controller_file_name
end
def get_binding
binding
end
end
# create empty shell file consisting of layout and a comment for where to insert new content. Use action_to_create
- # to infer the destination name controller_action.html and to customize the inserted place holder. Pass the
+ # to infer the destination name controller_action.html and to customize the inserted place holder. Pass the
# empty insert erb (rhtml) content in which will be rendered with appropriate controller and action values.
- # Valid options:
+ # Valid options:
# :write_to_file => true (write to file and return filename, if false then simply return generated contents)
# :template_source => source_for_template (use this source instead of reading from file)
# :content_hash => use this content_hash, otherwise it will scan the masterview template directory to create content_hash
def self.create_empty_shell_for_action(path_to_copy_shell_from, action_to_create, empty_insert_erb, options={} )
path = IOMgr.template.cleanup_path_get_relative_pathname(path_to_copy_shell_from).to_s