Sha256: bdc9ec446ee4e227a9f70a0a33bed4bbb04bf06379261c7aac1a46421e1ef498

Contents?: true

Size: 988 Bytes

Versions: 17

Compression:

Stored size: 988 Bytes

Contents

class ComponentGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('templates', __dir__)

  def add_component
    segments = name.underscore.split('/')
    fail("NAME must be of the form Family::ComponentName or family/component_name but got #{name.inspect}") if segments.size != 2
    @family, @comp = segments
    @family = @family.pluralize # Force plural
    @family_cst = @family.camelize.pluralize # Force plural
    @comp_cst = @comp.camelize # Tolerate singular and plural
    @args = args

    case @comp_cst
    when 'Destroy'
      template 'destroy.rb.erb', "app/components/#{@family}/#{@comp}.rb"
    when 'Edit'
      template 'edit.rb.erb', "app/components/#{@family}/#{@comp}.rb"
    when 'Form'
      template 'form.rb.erb', "app/components/#{@family}/#{@comp}.rb"
    when 'New'
      template 'new.rb.erb', "app/components/#{@family}/#{@comp}.rb"
    else
      template 'component.rb.erb', "app/components/#{@family}/#{@comp}.rb"
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
compony-0.5.2 lib/generators/component/component_generator.rb
compony-0.5.1 lib/generators/component/component_generator.rb
compony-0.5.0 lib/generators/component/component_generator.rb
compony-0.4.1 lib/generators/component/component_generator.rb
compony-0.4.0 lib/generators/component/component_generator.rb
compony-0.3.3 lib/generators/component/component_generator.rb
compony-0.3.2 lib/generators/component/component_generator.rb
compony-0.3.1 lib/generators/component/component_generator.rb
compony-0.3.0 lib/generators/component/component_generator.rb
compony-0.2.3 lib/generators/component/component_generator.rb
compony-0.2.2 lib/generators/component/component_generator.rb
compony-0.2.1 lib/generators/component/component_generator.rb
compony-0.2.0 lib/generators/component/component_generator.rb
compony-0.1.1 lib/generators/component/component_generator.rb
compony-0.1.0 lib/generators/component/component_generator.rb
compony-0.0.9 lib/generators/component/component_generator.rb
compony-0.0.8 lib/generators/component/component_generator.rb