Sha256: ec4f181d30a37281c4ad1c401e6db1cf8219ddc40a6b0dce279a4da90f351072

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'rubygems'
require 'templater'

module Generators
  extend Templater::Manifold
  desc "Build a staticmatic site"
  
  class Builder < Templater::Generator
    # Define source and desintation
    def self.source_root; Dir.pwd; end
    def destination_root; File.join(Dir.pwd, 'build'); end

    # Override template to ask staticmatic for the correct extension to output
    def self.template(name, *args, &block)
      return if args.first.include?('/layout/')
      return if File.basename(args.first)[0,1] == '_'
      
      if (args[0] === args[1])
        args[1] = args[0].gsub(File.extname(args.first), '').gsub('pages/', '')
      end
      
      super(name, *args, &block)
    end
    
    def self.file(name, *args, &block)
      return if args.first.include?('/sass/')
      args[1] = args[0].gsub('pages/', '') if (args[0] === args[1])
      super(name, *args, &block)
    end
    
    glob! "images",      [] # No templates
    glob! "javascripts", [] # No templates
    glob! "stylesheets", [] # No templates (Sass is pregenerated)
    glob! "pages",       %w(haml erb)
  end
  
  add :build, Builder
end

# Monkey-patch to use a dynamic renderer, not just ERb
class Templater::Actions::Template
  def render
    request_path = destination.gsub(File.join(Dir.pwd, 'build'), "")
    ::MerbProxy.new.get(request_path).body
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tdreyno-staticmatic-2.9.1 lib/builder.rb
tdreyno-staticmatic-2.9.3 lib/builder.rb
tdreyno-staticmatic-2.9.4 lib/builder.rb