Sha256: 278e80c5842a03e94e775e529877af624a37df6c88644f51d63a582f68e94ad5

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# =============================================================================
#  
# MODULE      : lib/folder_template/template_folder.rb
# PROJECT     : FolderTemplate
# DESCRIPTION : 
#
# Copyright (c) 2016, Marc-Antoine Argenton.  All rights reserved.
# =============================================================================

module FolderTemplate

  class TemplateFolder
    attr_reader :entries
    
    def initialize( path )
      @entries = _load_template( path )
    end
    
    def variables
      @variables ||= entries.each_with_object( Set.new ) do |e, variables|
        variables.merge( e.variables )
      end
    end

    def generate( fs, **env )
      entries.each do |entry|
        entry.generate( fs, env )
      end
    end
    

  private
    def _load_template( path )
      prefix = File.join( path, "" )
      
      Dir[File.join( path, "**", "*")].map do |source|
        filename = source.gsub( prefix, '' )
        content = File.read( source ) if !File.directory?( source )
        TemplateFolderEntry.new( filename, content )
      end
    end
  end # class TemplateFolder

end














Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
folder_template-0.1.1 lib/folder_template/template_folder.rb