lib/reality/generators/generator.rb
# Actually perform the generation of files from specified templates.
# Files are generated to the specified target directory. Any files that
# are not generated by this process are deleted. The files generated are
# based on the specified templates.
# The traversal starts from a root element of specified element_type and
# traverses all elements that are contained transitively by the root element.
# The templates then generate files from traversed elements.
Actually perform the generation of files from specified templates.
Files are generated to the specified target directory. Any files that
are not generated by this process are deleted. The files generated are
based on the specified templates.
The traversal starts from a root element of specified element_type and
traverses all elements that are contained transitively by the root element.
The templates then generate files from traversed elements.
Actually perform the generation of files from specified templates . Files are generated to the specified target directory . Any files that are not generated by this process are deleted . The files generated are based on the specified templates . The traversal starts from a root element of specified element_type and traverses all elements that are contained transitively by the root element . The templates then generate files from traversed elements .
def generate(element_type, element, directory, templates, filter)
        templates = load_templates_from_template_sets(templates) if templates.any? {|t| t.is_a?(Symbol) || t.is_a?(String)}
        unprocessed_files = (Dir["#{directory}/**/*.*"] + Dir["#{directory}/**/*"]).uniq
        element.pre_generate if element.respond_to?(:pre_generate)
        Generators.debug "Templates to process: #{templates.collect { |t| t.name }.inspect}"
        targets = {}
        collect_generation_targets(element_type, element, element, targets)
        templates.each do |template|
          Generators.debug "Evaluating template: #{template.name}"
          elements = targets[template.target]
          elements.each do |element_pair|
            element = element_pair[1]
            if template.applicable?(element_pair[0]) && (filter.nil? || filter.call(template.target, element))
              template.generate(directory, element, unprocessed_files)
            end
          end if elements
        end
        unprocessed_files.sort.reverse.each do |file|
          if File.directory?(file)
            if (Dir.entries(file) - %w(. ..)).empty?
              Generators.debug "Removing #{file} as no longer generated"
              FileUtils.rmdir file
            end
          else
            Generators.debug "Removing #{file} as no longer generated"
            FileUtils.rm_f file
          end
        end
        Generators.info 'Generator completed'
      end
def generate ( element_type , element , directory , templates , filter ) templates = load_templates_from_template_sets ( templates ) if templates . any? { | t | t . is_a? ( Symbol ) || t . is_a? ( String ) } unprocessed_files = ( Dir [ "#{directory}/**/*.*" ] + Dir [ "#{directory}/**/*" ] ) . uniq element . pre_generate if element . respond_to? ( :pre_generate ) Generators . debug "Templates to process: #{templates.collect { |t| t.name }.inspect}" targets = { } collect_generation_targets ( element_type , element , element , targets ) templates . each do | template | Generators . debug "Evaluating template: #{template.name}" elements = targets [ template . target ] elements . each do | element_pair | element = element_pair [ 1 ] if template . applicable? ( element_pair [ 0 ] ) && ( filter . nil? || filter . call ( template . target , element ) ) template . generate ( directory , element , unprocessed_files ) end end if elements end unprocessed_files . sort . reverse . each do | file | if File . directory? ( file ) if ( Dir . entries ( file ) - %w( . .. ) ) . empty? Generators . debug "Removing #{file} as no longer generated" FileUtils . rmdir file end else Generators . debug "Removing #{file} as no longer generated" FileUtils . rm_f file end end Generators . info 'Generator completed' end
Actually perform the generation of files from specified templates.
Actually perform the generation of files from specified templates .
element_type
<not_specific>
element
<not_specific>
directory
<not_specific>
templates
<not_specific>
filter
<not_specific>