Sha256: 358b9267bbb31f729ec8a6fe8c54cc89d32f34a605917f2aae19ad864b7d4d61

Contents?: true

Size: 2 KB

Versions: 30

Compression:

Stored size: 2 KB

Contents

module PowerStencil
  module Project

    module Templates

      def entity_type_templates_templates
        @entity_type_templates_templates ||= {}
      end

      def register_template_template_path_for_type(entity_type, path)
        if entity_type_templates_templates.include? entity_type
          logger.warn "There is already a template-template path registered for entity type '#{entity_type}': '#{entity_type_templates_templates[entity_type]}'."
        end
        raise PowerStencil::Error, "There is no template in path: '#{path}'" unless Dir.exist? path and File.readable? path
        raise PowerStencil::Error, "Trying to register a template for non existing type '#{entity_type}'" unless engine.available_entity_types.include? entity_type
        logger.debug "Registering '#{path}' as template for type '#{entity_type}'."
        entity_type_templates_templates[entity_type] = path
      end

      def generate_template_dir_for_entity(entity, force: false)
        unless entity_type_templates_templates[entity.type].nil?
          logger.debug "Generating entity dir for entity '#{entity.as_path}'"
          target_path = entity.templates_path
          render_entity_template_template_in entity, target_path, force: force
        end
      end

      def delete_template_dir_for_entity(entity, force: false)
        return unless force
        unless entity_type_templates_templates[entity.type].nil?
          logger.debug "Deleting entity files for entity '#{entity.as_path}'"
          target_path = entity.templates_path
          FileUtils.rmtree target_path unless target_path.nil? or target_path.empty?
        end
      end

      private

      def render_entity_template_template_in(entity, entity_dir_path, force: false)
        entity_engine.render_source entity_type_templates_templates[entity.type],
                                    entity_dir_path,
                                    overwrite_files: force,
                                    main_entry_point: entity.name
      end

    end

  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
power_stencil-0.10.0 lib/power_stencil/project/templates.rb
power_stencil-0.9.8 lib/power_stencil/project/templates.rb
power_stencil-0.9.7 lib/power_stencil/project/templates.rb
power_stencil-0.9.6 lib/power_stencil/project/templates.rb
power_stencil-0.9.5 lib/power_stencil/project/templates.rb
power_stencil-0.9.4 lib/power_stencil/project/templates.rb
power_stencil-0.9.3 lib/power_stencil/project/templates.rb
power_stencil-0.9.2 lib/power_stencil/project/templates.rb
power_stencil-0.9.1 lib/power_stencil/project/templates.rb
power_stencil-0.9.0 lib/power_stencil/project/templates.rb
power_stencil-0.8.14 lib/power_stencil/project/templates.rb
power_stencil-0.8.13 lib/power_stencil/project/templates.rb
power_stencil-0.8.12 lib/power_stencil/project/templates.rb
power_stencil-0.8.11 lib/power_stencil/project/templates.rb
power_stencil-0.8.10 lib/power_stencil/project/templates.rb
power_stencil-0.8.9 lib/power_stencil/project/templates.rb
power_stencil-0.8.8 lib/power_stencil/project/templates.rb
power_stencil-0.8.7 lib/power_stencil/project/templates.rb
power_stencil-0.8.6 lib/power_stencil/project/templates.rb
power_stencil-0.8.5 lib/power_stencil/project/templates.rb