Sha256: 1a6c97cbcf7f7a26b72680a6a86da8d0a1ec8e5775e0f9b0390e3f5a0350e9b2

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

module Kitabu
  module Templates
    TEMPLATES_ROOT = File.join(Kitabu::Base::GEM_ROOT, 'templates')
    DIRECTORIES = %w(text templates output)
    
    def self.process!(options)
      directories!(options)
      bundle_css!(options)
      files!(options)
      config!(options)
    end
    
    def self.directories!(options)
      FileUtils.mkdir(options[:path])
      
      DIRECTORIES.each do |d|
        FileUtils.mkdir File.join(options[:path], d)
      end
    end
    
    def self.files!(options)
      copy_file "Rakefile", "#{options[:path]}/Rakefile"
      copy_file "layouts/#{options[:layout]}/layout.css", "#{options[:path]}/templates/layout.css"
      copy_file "layouts/#{options[:layout]}/layout.html", "#{options[:path]}/templates/layout.html"
      copy_file "user.css", "#{options[:path]}/templates/user.css"
    end
    
    def self.config!(options)
      template = File.new(File.join(TEMPLATES_ROOT, 'config.yml')).read
      env = OpenStruct.new(options)
      contents = ERB.new(template).result env.instance_eval{binding}

      File.open(File.join(options[:path], 'config.yml'), 'w+') << contents
    end
    
    def self.bundle_css!(options)
      contents = Dir["#{TEMPLATES_ROOT}/themes/*.css"].collect do |file|
        File.read(file)
      end

      File.open("#{options[:path]}/templates/syntax.css", "w+") << contents.join("\n\n")
    end
    
    private
      def self.copy_file(from, to)
        FileUtils.cp File.join(TEMPLATES_ROOT, from), to
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fnando-kitabu-0.3.0 lib/kitabu/templates.rb
fnando-kitabu-0.3.1 lib/kitabu/templates.rb
fnando-kitabu-0.3.2 lib/kitabu/templates.rb
fnando-kitabu-0.3.3 lib/kitabu/templates.rb