Sha256: f43575568587fe0a1e11a86afdc1cf2738571c57dce657cae61ee87a1a9b5d92

Contents?: true

Size: 1.19 KB

Versions: 14

Compression:

Stored size: 1.19 KB

Contents

module Chanko
  module Generators
    class UnitGenerator < Rails::Generators::NamedBase
      ASSETS_TYPES = %w[images javascripts stylesheets]

      source_root File.expand_path("../templates", __FILE__)

      def create_unit_directory
        empty_directory(directory)
      end

      def create_unit_file
        template("unit.rb.erb", "#{directory}/#{file_name}.rb")
      end

      def create_views_directory
        create_file("#{directory}/views/.gitkeep", "")
      end

      ASSETS_TYPES.each do |type|
        define_method("create_#{type}_directory") do
          create_file("#{directory}/#{type}/.gitkeep", "")
        end
      end

      ASSETS_TYPES.each do |type|
        define_method("create_#{type}_symlink") do
          create_assets_symlink(type)
        end
      end

      private

      def create_assets_symlink(type)
        from = "app/assets/#{type}/#{directory_name}/#{file_name}"
        to   = "../../../../#{directory}/#{type}"
        create_link(from, to)
      end

      def directory
        "#{Chanko::Config.units_directory_path}/#{file_name}"
      end

      def directory_name
        Chanko::Config.units_directory_path.split("/").last
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
chanko-2.3.0 lib/generators/chanko/unit/unit_generator.rb
chanko-2.2.1 lib/generators/chanko/unit/unit_generator.rb
chanko-2.2.0 lib/generators/chanko/unit/unit_generator.rb
chanko-2.1.1 lib/generators/chanko/unit/unit_generator.rb
chanko-2.1.0 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.8 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.7 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.6 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.5 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.4 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.3 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.2 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.1 lib/generators/chanko/unit/unit_generator.rb
chanko-2.0.0 lib/generators/chanko/unit/unit_generator.rb