Sha256: bba171eb315db6c5b5a7b7fa658f02a7582a0d34b57a01d05447347b1978668b

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

require "thor"
require "extlib"

module Hexx
  module Generators

    # Base class for scaffolders.
    class Base < Thor::Group
      include Thor::Actions

      argument :project
      argument :name

      def self.source_root(file = __FILE__)
        root = File.dirname File.expand_path(file)
        @source_root ||= File.join(root, "templates")
      end

      private

      def gem_name
        @gem_name ||= project.snake_case
      end

      def module_name
        @module_name ||= project.camel_case
      end

      def class_name
        @class_name ||= name.camel_case
      end

      def file_name
        @file_name ||= name.snake_case
      end

      def action_type(string)
        return @action_type if @action_type
        list = string.split(":")
        list.count > 1 ? list.first.downcase : "get"
      end

      def action_name(string)
        string.split(":").last.downcase
      end

      def inject_template_into_file(source, file, options)
        source  = File.expand_path(find_in_source_paths(source.to_s))
        context = instance_eval("binding")
        content = ERB.new(::File.binread(source), nil, "-", "@output_buffer")
          .result(context)

        inject_into_file file, options do
          content
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hexx-1.1.1 lib/generators/base.rb
hexx-1.1.0 lib/generators/base.rb
hexx-1.0.2 lib/generators/base.rb
hexx-1.0.1 lib/generators/base.rb
hexx-1.0.0 lib/generators/base.rb
hexx-0.1.1 lib/generators/base.rb
hexx-0.1.0 lib/generators/base.rb
hexx-0.0.1 lib/generators/base.rb