Sha256: a3d43f4c3c8892514a8e0562674bd98afce41f13f1a9776078bf601904a00536

Contents?: true

Size: 925 Bytes

Versions: 6

Compression:

Stored size: 925 Bytes

Contents

require 'rails/generators'
class CoffeescriptGenerator < Rails::Generators::NamedBase

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

  desc "This generator creates a coffee script file at app/javascript/packs"

  argument :functions, type: :array, default: [],
                                     banner: "functionOne functionTwo"

  attr_reader :namespace

  def copy_template_file
    @namespace = class_name.split("::")
    @namespace.pop
    @namespace = @namespace.join("::")
    template "coffeescript.coffee.erb", file_path
  end

  private

  def function_name
    file_name.camelize(:lower)
  end

  def file_path
    Rails.root.join("app/javascript/packs", namespace_path, "#{file_name}.coffee")
  end

  def namespace_path
    if namespace.blank?
      return ""
    else
      namespace.split("::").map(&:underscore).join("/") + "/"
    end
  end

  def singular_name
    super.singularize
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
orthodox-0.3.6 lib/generators/coffeescript/coffeescript_generator.rb
orthodox-0.3.5 lib/generators/coffeescript/coffeescript_generator.rb
orthodox-0.3.4 lib/generators/coffeescript/coffeescript_generator.rb
orthodox-0.3.3 lib/generators/coffeescript/coffeescript_generator.rb
orthodox-0.3.2 lib/generators/coffeescript/coffeescript_generator.rb
orthodox-0.3.1 lib/generators/coffeescript/coffeescript_generator.rb