Sha256: 84dab330d232d21c34de9fea571daee1e62012be19c94aeb5698fe66ed286359

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 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

    public_files_glob = File.join(source_root, "public", "{images,javascripts,stylesheets}", '**/*')
    Dir[public_files_glob].each do |action|
      next if File.directory?(action)
      action = action.sub("#{source_root}/", '')
      file(action.downcase.gsub(/[^a-z0-9]+/, '_').to_sym, action, action.gsub('public/', ''))
    end

    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

5 entries across 5 versions & 1 rubygems

Version Path
tdreyno-staticmatic-2.10.0 lib/builder.rb
tdreyno-staticmatic-2.11.0 lib/builder.rb
tdreyno-staticmatic-2.11.1 lib/staticmatic/builder.rb
tdreyno-staticmatic-2.9.6 lib/builder.rb
tdreyno-staticmatic-2.9.7 lib/builder.rb