Padrino Plugin Generator Templates produce wrong output with underscores #924

Closed
jamespedid opened this Issue Aug 29, 2012 · 4 comments

Comments

Projects
None yet
4 participants

I'm using the latest copy of Padrino and I'm running into a multitude of problems building independent-sub applications to be installed to a currently existing application. In particular, the generators are creating the wrong things when underscores are used. The normal project files are contained under the name without the underscore, and the model files are stored in the folder with an underscore.

Try this on for size:

project orm: 'datamapper', test: 'cucumber', script: 'dojo',
        renderer: 'haml', stylesheet: 'scss'

run_bundler

app :general_ledger do
  generate :model, 'ledger name:string description:text'
  generate :model, 'chart_of_accounts name:string description:text'
  generate :model, 'account_group name:string description:text chart_of_accounts_id'
  generate :model, 'account_type name:string description:text'
  generate :model, 'account name:string description:text account_type_id:integer account_group_id:integer'
end

rake 'dm:auto:upgrade'

Ideally, I should be able to pick up the app..end and place it into its own file, and then simply create a sub-application using this. However this is being hindered by the underscore problem.

Here is my command prompt output:

C:\Users\Jim\RubymineProjects\mri_reboot>padrino g project test --template C:/users/jim/rubymineprojects/mri_reboot/mri_
dev/test_plugin.rb
       apply  C:/users/jim/rubymineprojects/mri_reboot/mri_dev/test_plugin.rb
  => Executing: padrino-gen project test --orm=datamapper --renderer=haml --script=dojo --stylesheet=scss --test=cucumbe
r -r=C:/Users/Jim/RubymineProjects/mri_reboot
      create
      create  .gitignore
      create  config.ru
      create  config/apps.rb
      create  config/boot.rb
      create  public/favicon.ico
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  tmp
      create  .components
      create  app
      create  app/app.rb
      create  app/controllers
      create  app/helpers
      create  app/views
      create  app/views/layouts
      create  Gemfile
    applying  datamapper (orm)...
       apply  orms/datamapper
      insert  Gemfile
      insert  Gemfile
      insert  Gemfile
      insert  Gemfile
      insert  Gemfile
      insert  Gemfile
      insert  Gemfile
      create  config/database.rb
      insert  config/boot.rb
    applying  cucumber (test)...
       apply  tests/cucumber
       apply    tests/rspec
      insert  Gemfile
      insert  Gemfile
      insert  Gemfile
      create  features/support/env.rb
      create  features/support/url.rb
      create  features/add.feature
      create  features/step_definitions/add_steps.rb
      create  cucumber.yml
      insert  Gemfile
      create  spec/spec_helper.rb
      create  spec/spec.rake
    skipping  mock component...
    applying  dojo (script)...
       apply  scripts/dojo
      create  public/javascripts/dojo.js
      create  public/javascripts/dojo-ujs.js
      create  public/javascripts/application.js
    applying  haml (renderer)...
       apply  renderers/haml
      insert  Gemfile
    applying  scss (stylesheet)...
       apply  stylesheets/scss
      insert  Gemfile
      insert  app/app.rb
      create  lib/scss_init.rb
      create  app/stylesheets
   identical  .components

=================================================================
test is ready for development!
=================================================================
$ cd C:/Users/Jim/RubymineProjects/mri_reboot/test
$ bundle install
=================================================================

  Bundling application dependencies using bundler...
         run    bundle install from "."
Fetching gem metadata from http://rubygems.org/........
Using rake (0.9.2.2)
Using i18n (0.6.0)
Using multi_json (1.3.6)
Using activesupport (3.2.8)
Using addressable (2.2.8)
Using builder (3.0.0)
Using bundler (1.1.4)
Using mime-types (1.19)
Using nokogiri (1.5.5)
Using rack (1.4.1)
Using rack-test (0.6.1)
Using ffi (1.1.5)
Using childprocess (0.3.5)
Using libwebsocket (0.1.5)
Using rubyzip (0.9.9)
Using selenium-webdriver (2.25.0)
Using xpath (0.1.4)
Using capybara (1.1.2)
Using diff-lcs (1.1.3)
Using json (1.7.5)
Using gherkin (2.11.2)
Using cucumber (1.2.1)
Using data_objects (0.10.8)
Using dm-core (1.2.0)
Using dm-aggregates (1.2.0)
Using dm-constraints (1.2.0)
Using dm-do-adapter (1.2.0)
Using dm-migrations (1.2.0)
Using do_sqlite3 (0.10.8)
Using dm-sqlite-adapter (1.2.0)
Using dm-timestamps (1.2.0)
Using dm-validations (1.2.0)
Using haml (3.1.7)
Using url_mount (0.2.1)
Using http_router (0.10.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.3.3)
Using rack-protection (1.2.0)
Using tilt (1.3.3)
Using sinatra (1.3.3)
Using thor (0.15.4)
Using padrino-core (0.10.7)
Using padrino-helpers (0.10.7)
Using padrino-admin (0.10.7)
Using padrino-cache (0.10.7)
Using padrino-gen (0.10.7)
Using padrino-mailer (0.10.7)
Using padrino (0.10.7)
Using rspec-core (2.11.1)
Using rspec-expectations (2.11.2)
Using rspec-mocks (2.11.2)
Using rspec (2.11.0)
Using sass (3.2.1)
Using sinatra-flash (0.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
  => Executing: padrino-gen app general_ledger -r=C:/Users/Jim/RubymineProjects/mri_reboot/test
      create  generalledger
      create  generalledger/app.rb
      create  generalledger/controllers
      create  generalledger/helpers
      create  generalledger/views
      create  generalledger/views/layouts
      create  public/generalledger
      append  config/apps.rb

=================================================================
Your GeneralLedger application has been installed.
=================================================================
This application has been mounted to /generalledger
You can configure a different path by editing 'config/apps.rb
=================================================================

  => Executing: padrino-gen model ledger name:string description:text -r=C:/Users/Jim/RubymineProjects/mri_reboot/test -
-app=general_ledger

=================================================================
Unable to locate 'GeneralLedger' application        =================================================================

       apply  orms/datamapper
       apply  tests/cucumber
       apply    tests/rspec
      create  general_ledger/models/ledger.rb
      create  spec/general_ledger/models/ledger_spec.rb
      create  db/migrate/001_create_ledgers.rb
  => Executing: padrino-gen model chart_of_accounts name:string description:text -r=C:/Users/Jim/RubymineProjects/mri_re
boot/test --app=general_ledger
       apply  orms/datamapper
       apply  tests/cucumber
       apply    tests/rspec
      create  general_ledger/models/chart_of_accounts.rb
      create  spec/general_ledger/models/chart_of_accounts_spec.rb
      create  db/migrate/002_create_chart_of_accounts.rb
  => Executing: padrino-gen model account_group name:string description:text chart_of_accounts_id -r=C:/Users/Jim/Rubymi
neProjects/mri_reboot/test --app=general_ledger
       apply  orms/datamapper
       apply  tests/cucumber
       apply    tests/rspec
(eval):72:in `block in create_model_file': undefined method `underscore' for nil:NilClass (NoMethodError)
        from (eval):72:in `map'
        from (eval):72:in `create_model_file'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/padrino-gen-0.10.7/lib/padrino-gen/generators/model.rb:53:in `create_mo
del'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `block in invoke_all'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `map'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `invoke_all'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/group.rb:238:in `dispatch'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/padrino-gen-0.10.7/lib/padrino-gen/generators/cli.rb:51:in `setup'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `block in invoke_all'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `each'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `map'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `invoke_all'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/group.rb:238:in `dispatch'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/padrino-gen-0.10.7/bin/padrino-gen:16:in `<main>'
  => Executing: padrino-gen model account_type name:string description:text -r=C:/Users/Jim/RubymineProjects/mri_reboot/
test --app=general_ledger
       apply  orms/datamapper
       apply  tests/cucumber
       apply    tests/rspec
      create  general_ledger/models/account_type.rb
      create  spec/general_ledger/models/account_type_spec.rb
      create  db/migrate/003_create_account_types.rb
  => Executing: padrino-gen model account name:string description:text account_type_id:integer account_group_id:integer
-r=C:/Users/Jim/RubymineProjects/mri_reboot/test --app=general_ledger
       apply  orms/datamapper
       apply  tests/cucumber
       apply    tests/rspec
      create  general_ledger/models/account.rb
      create  spec/general_ledger/models/account_spec.rb
      create  db/migrate/004_create_accounts.rb
=> Executing Rake dm:auto:upgrade ...
<= dm:auto:upgrade executed

=================================================================
test is ready for development!
=================================================================
$ cd ./test
$ bundle install
=================================================================


C:\Users\Jim\RubymineProjects\mri_reboot>

halfdan commented Nov 26, 2012

I can confirm this with even fewer steps:

padrino g project foo -d datamapper
cd foo
padrino g app blog
padrino g model --app=blog posts title content

leads to:

apply  orms/datamapper
(eval):72:in `block in create_model_file': undefined method `underscore' for nil:NilClass (NoMethodError)
    from (eval):72:in `map'
    from (eval):72:in `create_model_file'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/padrino-gen-0.10.7/lib/padrino-gen/generators/model.rb:53:in `create_model'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `block in invoke_all'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `each'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `map'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `invoke_all'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/group.rb:238:in `dispatch'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/padrino-gen-0.10.7/lib/padrino-gen/generators/cli.rb:51:in `setup'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `block in invoke_all'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `each'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `map'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/invocation.rb:126:in `invoke_all'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/group.rb:238:in `dispatch'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
    from /home/halfdan/.rvm/gems/ruby-1.9.3-p194@mruby.io/gems/padrino-gen-0.10.7/bin/padrino-gen:16:in `<main>'

Any help?

halfdan commented Nov 27, 2012

O.K., so I discussed this with @skade today. The reason why this is failing is because the model generator doesn't automatically assume "String" as default datatype (or any really). So @jamespedid and I made the same mistake and assumed String would be the default datatype chosen if none is given.

That being figured out, I think the generator should either not fail that hard and print out a proper text message or do it like Rails and assume "String" as the default datatype.

achiu was assigned Jan 5, 2013

achiu closed this in 33cf159 Jan 12, 2013

Owner

achiu commented Jan 12, 2013

Looks like there were two separate issues here:

  • app generation isn't respecting the underscores
  • model generation with fields missing types should default to string.

These two commits should address these issues. Please re-open if this doesn't solve it 😢

Member

dariocravero commented Jan 12, 2013

@achiu see #1006.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment