padrino-gen 0.11.2 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,7 @@ module Padrino
45
45
  path = File.expand_path(File.dirname(__FILE__) + "/components/#{component.to_s.pluralize}/#{choice}.rb")
46
46
  say_status :apply, "#{component.to_s.pluralize}/#{choice}"
47
47
  shell.padding += 1
48
- instance_eval(open(path).read)
48
+ instance_eval(File.read(path))
49
49
  shell.padding -= 1
50
50
  end
51
51
 
@@ -15,7 +15,7 @@ end
15
15
  # set :foo, :bar
16
16
  # end
17
17
  #
18
- def app(app = nil &blk)
18
+ def app(app = nil, &blk)
19
19
  @app ||= block_given? ? app.instance_eval(&blk) : app
20
20
  @app ||= Padrino.application
21
21
  end
@@ -14,7 +14,7 @@ class MiniTest::Unit::TestCase
14
14
  # set :foo, :bar
15
15
  # end
16
16
  #
17
- def app(app = nil &blk)
17
+ def app(app = nil, &blk)
18
18
  @app ||= block_given? ? app.instance_eval(&blk) : app
19
19
  @app ||= Padrino.application
20
20
  end
@@ -19,7 +19,7 @@ class Riot::Situation
19
19
  # set :foo, :bar
20
20
  # end
21
21
  #
22
- def app(app = nil &blk)
22
+ def app(app = nil, &blk)
23
23
  @app ||= block_given? ? app.instance_eval(&blk) : app
24
24
  @app ||= Padrino.application
25
25
  end
@@ -15,7 +15,7 @@ end
15
15
  # set :foo, :bar
16
16
  # end
17
17
  #
18
- def app(app = nil &blk)
18
+ def app(app = nil, &blk)
19
19
  @app ||= block_given? ? app.instance_eval(&blk) : app
20
20
  @app ||= Padrino.application
21
21
  end
@@ -16,7 +16,7 @@ class Test::Unit::TestCase
16
16
  # set :foo, :bar
17
17
  # end
18
18
  #
19
- def app(app = nil &blk)
19
+ def app(app = nil, &blk)
20
20
  @app ||= block_given? ? app.instance_eval(&blk) : app
21
21
  @app ||= Padrino.application
22
22
  end
@@ -14,7 +14,7 @@ class Test::Unit::TestCase
14
14
  # set :foo, :bar
15
15
  # end
16
16
  #
17
- def app(app = nil &blk)
17
+ def app(app = nil, &blk)
18
18
  @app ||= block_given? ? app.instance_eval(&blk) : app
19
19
  @app ||= Padrino.application
20
20
  end
@@ -5,4 +5,5 @@ bin/*
5
5
  vendor/gems/*
6
6
  !vendor/gems/cache/
7
7
  .sass-cache/*
8
- db/*.db
8
+ db/*.db
9
+ .*.sw*
@@ -120,7 +120,7 @@ module Padrino
120
120
  #
121
121
  # @api private
122
122
  def git_author_name
123
- git_author_name = `git config user.name`.chomp
123
+ git_author_name = `git config user.name`.chomp rescue ''
124
124
  git_author_name.empty? ? "TODO: Write your name" : git_author_name
125
125
  end
126
126
 
@@ -128,7 +128,7 @@ module Padrino
128
128
  #
129
129
  # @api private
130
130
  def git_author_email
131
- git_author_email = `git config user.email`.chomp
131
+ git_author_email = `git config user.email`.chomp rescue ''
132
132
  git_author_email.empty? ? "TODO: Write your email address" : git_author_email
133
133
  end
134
134
  end # Project
@@ -1,4 +1,4 @@
1
- # <%=name.camelcase%>
1
+ # <%= @project_name %>
2
2
 
3
3
  A padrino gem
4
4
 
@@ -13,7 +13,7 @@ gem '<%=name%>'
13
13
  and mount the app in your `apps.rb`:
14
14
 
15
15
  ```ruby
16
- Padrino.mount("<%=name.camelcase%>::App").to("/<%=name%>")
16
+ Padrino.mount("<%= @project_name %>::App").to("/<%=name%>")
17
17
  ```
18
18
 
19
19
  ## Development
@@ -26,4 +26,4 @@ $ bundle exec padrino start
26
26
  ```
27
27
 
28
28
  The Rakefile also works like the normal Padrino one and supports all standard
29
- components.
29
+ components.
@@ -11,9 +11,9 @@ Gem::Specification.new do |gem|
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = <%=name.underscore.inspect%>
14
+ gem.name = <%= name.downcase.inspect %>
15
15
  gem.require_paths = ["lib", "app"]
16
- gem.version = <%=name.camelcase%>::VERSION
16
+ gem.version = <%= @project_name %>::VERSION
17
17
 
18
18
  gem.add_dependency "padrino-core"
19
19
  end
@@ -1,3 +1,3 @@
1
- module <%=name.camelcase%>
1
+ module <%= @project_name %>
2
2
  VERSION = '0.0.1'
3
- end
3
+ end
@@ -1,6 +1,6 @@
1
1
  require 'padrino-core'
2
2
 
3
- module <%=name.camelcase%>
3
+ module <%= @project_name %>
4
4
  extend Padrino::Module
5
- gem! <%=name.downcase.inspect%>
6
- end
5
+ gem! <%= name.downcase.inspect %>
6
+ end
@@ -84,12 +84,26 @@ $(function(){
84
84
  var verb = element.data('method');
85
85
  var url = element.attr('href');
86
86
  var form = $('<form method="post" action="'+url+'"></form>');
87
+ var csrf_token = $('meta[name=csrf-token]').attr('content');
88
+ var csrf_param = $('meta[name=csrf-param]').attr('content');
87
89
  form.hide().appendTo('body');
88
90
  if (verb !== 'post') {
89
91
  var field = '<input type="hidden" name="_method" value="' + verb + '" />';
90
92
  form.append(field);
91
93
  }
94
+ if (csrf_param !== undefined && csrf_token !== undefined) {
95
+ var field = '<input type="hidden" name="' + csrf_param + '" value="' + csrf_token + '" />';
96
+ form.append(field);
97
+ }
92
98
  form.submit();
93
99
  }
94
100
  };
101
+
102
+ // Every xhr request is sent along with the CSRF token.
103
+ $.ajaxPrefilter(function(options, originalOptions, xhr) {
104
+ if (options.verb !== 'GET') {
105
+ var token = $('meta[name="csrf-token"]').attr('content');
106
+ if (token) xhr.setRequestHeader('X-CSRF-Token', token);
107
+ }
108
+ });
95
109
  });
@@ -1,7 +1,12 @@
1
1
  if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
2
2
  # Fixes for Yardoc YRI Building
3
- module ActiveRecord; end unless defined?(ActiveRecord)
4
- class ActiveRecord::Schema; end unless defined?(ActiveRecord::Schema)
3
+ begin
4
+ require 'active_record'
5
+ require 'active_record/schema'
6
+ rescue LoadError
7
+ module ActiveRecord; end unless defined?(ActiveRecord)
8
+ class ActiveRecord::Schema; end unless defined?(ActiveRecord::Schema)
9
+ end
5
10
 
6
11
  namespace :ar do
7
12
  namespace :create do
@@ -3,13 +3,13 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
3
3
  namespace :auto do
4
4
  desc "Perform automigration (reset your db data)"
5
5
  task :migrate => :environment do
6
- ::DataMapper.auto_migrate!
6
+ ::DataMapper.repository.auto_migrate!
7
7
  puts "<= dm:auto:migrate executed"
8
8
  end
9
9
 
10
10
  desc "Perform non destructive automigration"
11
11
  task :upgrade => :environment do
12
- ::DataMapper.auto_upgrade!
12
+ ::DataMapper.repository.auto_upgrade!
13
13
  puts "<= dm:auto:upgrade executed"
14
14
  end
15
15
  end
@@ -55,34 +55,15 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
55
55
  database = config[:database] || config[:path].sub(/\//, "")
56
56
  charset = config[:charset] || ENV['CHARSET'] || 'utf8'
57
57
  collation = config[:collation] || ENV['COLLATION'] || 'utf8_unicode_ci'
58
- puts "=> Creating database '#{database}'"
59
- case config[:adapter]
60
- when 'postgres'
61
- arguments = []
62
- arguments << "--encoding=#{charset}" if charset
63
- arguments << "--host=#{host}" if host
64
- arguments << "--username=#{user}" if user
65
- arguments << database
66
- system("createdb", *arguments)
67
- puts "<= dm:create executed"
68
- when 'mysql'
69
- arguments = ["--user=#{user}"]
70
- arguments << "--password=#{password}" unless password.blank?
71
-
72
- unless %w[127.0.0.1 localhost].include?(host)
73
- arguments << "--host=#{host}"
74
- end
75
-
76
- arguments << '-e'
77
- arguments << "CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}"
78
58
 
79
- system('mysql',*arguments)
80
- puts "<= dm:create executed"
81
- when 'sqlite3'
82
- DataMapper.setup(DataMapper.repository.name, config)
83
- else
84
- raise "Adapter #{config[:adapter]} not supported for creating databases yet."
59
+ puts "=> Creating database '#{database}'"
60
+ if config[:adapter] == 'sqlite3'
61
+ DataMapper.setup(DataMapper.repository.name, config)
62
+ else
63
+ # require 'padrino-gen/padrino-tasks/sql-helpers'
64
+ Padrino::Generators::SqlHelpers.create_db(config[:adapter], user, password, host, database, charset, collation)
85
65
  end
66
+ puts "<= dm:create executed"
86
67
  end
87
68
 
88
69
  desc "Drop the database (postgres and mysql only)"
@@ -90,33 +71,14 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
90
71
  config = DataMapper.repository.adapter.options.symbolize_keys
91
72
  user, password, host = config[:user], config[:password], config[:host]
92
73
  database = config[:database] || config[:path].sub(/\//, "")
93
- puts "=> Dropping database '#{database}'"
94
- case config[:adapter]
95
- when 'postgres'
96
- arguments = []
97
- arguments << "--host=#{host}" if host
98
- arguments << "--username=#{user}" if user
99
- arguments << database
100
- system("dropdb", *arguments)
101
- puts "<= dm:drop executed"
102
- when 'mysql'
103
- arguments = ["--user=#{user}"]
104
- arguments << "--password=#{password}" unless password.blank?
105
74
 
106
- unless %w[127.0.0.1 localhost].include?(host)
107
- arguments << "--host=#{host}"
108
- end
109
-
110
- arguments << '-e'
111
- arguments << "DROP DATABASE IF EXISTS #{database}"
112
-
113
- system('mysql',*arguments)
114
- puts "<= dm:drop executed"
115
- when 'sqlite3'
116
- File.delete(config[:path]) if File.exist?(config[:path])
117
- else
118
- raise "Adapter #{config[:adapter]} not supported for dropping databases yet."
75
+ puts "=> Dropping database '#{database}'"
76
+ if config[:adapter] == 'sqlite3'
77
+ File.delete(config[:path]) if File.exist?(config[:path])
78
+ else
79
+ Padrino::Generators::SqlHelpers.drop_db(config[:adapter], user, password, host, database)
119
80
  end
81
+ puts "<= dm:drop executed"
120
82
  end
121
83
 
122
84
  desc "Drop the database, migrate from scratch and initialize with the seed data"
@@ -67,7 +67,7 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
67
67
  # Helper to retrieve a list of models.
68
68
  def get_mongoid_models
69
69
  documents = []
70
- Dir['{app,.}/models/*.rb'].sort.each do |file|
70
+ Dir['{app,.}/models/**/*.rb'].sort.each do |file|
71
71
  model_path = file[0..-4].split('/')[2..-1]
72
72
 
73
73
  begin
@@ -36,7 +36,43 @@ if PadrinoTasks.load?(:sequel, defined?(Sequel))
36
36
 
37
37
  desc "Perform migration up to latest migration available"
38
38
  task :migrate => 'sq:migrate:up'
39
+
40
+ desc "Create the database"
41
+ task :create => :environment do
42
+ config = Sequel::Model.db.opts
43
+ user, password, host = config[:user], config[:password], config[:host]
44
+ database = config[:database]
45
+ charset = config[:charset] || ENV['CHARSET'] || 'utf8'
46
+ collation = config[:collation] || ENV['COLLATION'] || 'utf8_unicode_ci'
47
+
48
+ puts "=> Creating database '#{database}'"
49
+ if config[:adapter] == 'sqlite3'
50
+ ::Sequel.sqlite(database)
51
+ else
52
+ require 'padrino-gen/padrino-tasks/sql-helpers'
53
+ Padrino::Generators::SqlHelpers.create_db(config[:adapter], user, password, host, database, charset, collation)
54
+ end
55
+ puts "<= sq:create executed"
56
+ end
57
+
58
+ desc "Drop the database (postgres and mysql only)"
59
+ task :drop => :environment do
60
+ config = ::Sequel::Model.db.opts
61
+ user, password, host, database = config[:user], config[:password], config[:host], config[:database]
62
+
63
+ ::Sequel::Model.db.disconnect
64
+
65
+ puts "=> Dropping database '#{database}'"
66
+ if config[:adapter] == 'sqlite3'
67
+ File.delete(database) if File.exist?(database)
68
+ else
69
+ Padrino::Generators::SqlHelpers.drop_db(config[:adapter], user, password, host, database)
70
+ end
71
+ puts "<= sq:drop executed"
72
+ end
73
+
39
74
  end
40
75
 
41
76
  task 'db:migrate' => 'sq:migrate'
77
+ task 'db:reset' => ['sq:drop', 'sq:create', 'sq:migrate', 'seed']
42
78
  end
@@ -0,0 +1,56 @@
1
+ module Padrino
2
+ module Generators
3
+ module SqlHelpers
4
+ def self.create_db(adapter, user, password, host, database, charset, collation)
5
+ case adapter
6
+ when 'postgres'
7
+ arguments = []
8
+ arguments << "--encoding=#{charset}" if charset
9
+ arguments << "--host=#{host}" if host
10
+ arguments << "--username=#{user}" if user
11
+ arguments << database
12
+ system("createdb", *arguments)
13
+ when 'mysql'
14
+ arguments = ["--user=#{user}"]
15
+ arguments << "--password=#{password}" unless password.blank?
16
+
17
+ unless %w[127.0.0.1 localhost].include?(host)
18
+ arguments << "--host=#{host}"
19
+ end
20
+
21
+ arguments << '-e'
22
+ arguments << "CREATE DATABASE #{database} DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}"
23
+
24
+ system('mysql',*arguments)
25
+ else
26
+ raise "Adapter #{adapter} not supported for creating databases yet."
27
+ end
28
+ end
29
+
30
+ def self.drop_db(adapter, user, password, host, database)
31
+ case adapter
32
+ when 'postgres'
33
+ arguments = []
34
+ arguments << "--host=#{host}" if host
35
+ arguments << "--username=#{user}" if user
36
+ arguments << database
37
+ system("dropdb", *arguments)
38
+ when 'mysql'
39
+ arguments = ["--user=#{user}"]
40
+ arguments << "--password=#{password}" unless password.blank?
41
+
42
+ unless %w[127.0.0.1 localhost].include?(host)
43
+ arguments << "--host=#{host}"
44
+ end
45
+
46
+ arguments << '-e'
47
+ arguments << "DROP DATABASE IF EXISTS #{database}"
48
+
49
+ system('mysql',*arguments)
50
+ else
51
+ raise "Adapter #{adapter} not supported for dropping databases yet."
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -41,6 +41,19 @@ describe "ProjectGenerator" do
41
41
  assert_match_in_file("Padrino.mount('ProjectCom::WsDci2011', :app_file => Padrino.root('ws_dci_2011/app.rb')).to('/ws_dci_2011')", "#{@apptmp}/project.com/config/apps.rb")
42
42
  end
43
43
 
44
+ should "generate nested path with dashes in name" do
45
+ capture_io { generate(:project, 'sample-project', "--root=#{@apptmp}") }
46
+ assert_file_exists("#{@apptmp}/sample-project")
47
+ assert_match_in_file(/module SampleProject/, "#{@apptmp}/sample-project/app/app.rb")
48
+ assert_match_in_file(/class App < Padrino::Application/, "#{@apptmp}/sample-project/app/app.rb")
49
+ assert_match_in_file("Padrino.mount('SampleProject::App', :app_file => Padrino.root('app/app.rb')).to('/')", "#{@apptmp}/sample-project/config/apps.rb")
50
+ capture_io { generate(:app, 'ws-dci-2011', "--root=#{@apptmp}/sample-project") }
51
+ assert_file_exists("#{@apptmp}/sample-project/ws_dci_2011")
52
+ assert_match_in_file(/module SampleProject/, "#{@apptmp}/sample-project/ws_dci_2011/app.rb")
53
+ assert_match_in_file(/class WsDci2011 < Padrino::Application/, "#{@apptmp}/sample-project/ws_dci_2011/app.rb")
54
+ assert_match_in_file("Padrino.mount('SampleProject::WsDci2011', :app_file => Padrino.root('ws_dci_2011/app.rb')).to('/ws_dci_2011')", "#{@apptmp}/sample-project/config/apps.rb")
55
+ end
56
+
44
57
  should "raise an Error when given invalid constant names" do
45
58
  assert_raises(::NameError) { capture_io { generate(:project, "123asdf", "--root=#{@apptmp}") } }
46
59
  assert_raises(::NameError) { capture_io { generate(:project, "./sample_project", "--root=#{@apptmp}") } }
@@ -96,6 +109,22 @@ describe "ProjectGenerator" do
96
109
  assert_file_exists("#{@apptmp}/sample_gem/README.md")
97
110
  end
98
111
 
112
+ should "generate gemspec and special files with dashes in name" do
113
+ capture_io { generate(:project,'sample-gem', '--gem', "--root=#{@apptmp}") }
114
+ assert_file_exists("#{@apptmp}/sample-gem/sample-gem.gemspec")
115
+ assert_file_exists("#{@apptmp}/sample-gem/README.md")
116
+ assert_match_in_file(/\/lib\/sample-gem\/version/,"#{@apptmp}/sample-gem/sample-gem.gemspec")
117
+ assert_match_in_file(/"sample-gem"/,"#{@apptmp}/sample-gem/sample-gem.gemspec")
118
+ assert_match_in_file(/SampleGem::VERSION/,"#{@apptmp}/sample-gem/sample-gem.gemspec")
119
+ assert_match_in_file(/^# SampleGem/,"#{@apptmp}/sample-gem/README.md")
120
+ assert_match_in_file(/SampleGem::App/,"#{@apptmp}/sample-gem/README.md")
121
+ assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample-gem/lib/sample-gem.rb")
122
+ assert_match_in_file(/gem! "sample-gem"/,"#{@apptmp}/sample-gem/lib/sample-gem.rb")
123
+ assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample-gem/lib/sample-gem/version.rb")
124
+ assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample-gem/app/app.rb")
125
+ assert_match_in_file(/class App/,"#{@apptmp}/sample-gem/app/app.rb")
126
+ end
127
+
99
128
  should "not create models folder if no orm is chosen" do
100
129
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '--orm=none') }
101
130
  assert_no_dir_exists("#{@apptmp}/sample_project/models")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-05-21 00:00:00.000000000 Z
15
+ date: 2013-07-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: padrino-core
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - '='
23
23
  - !ruby/object:Gem::Version
24
- version: 0.11.2
24
+ version: 0.11.3
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.11.2
32
+ version: 0.11.3
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +133,7 @@ files:
133
133
  - lib/padrino-gen/padrino-tasks/mongoid.rb
134
134
  - lib/padrino-gen/padrino-tasks/mongomapper.rb
135
135
  - lib/padrino-gen/padrino-tasks/sequel.rb
136
+ - lib/padrino-gen/padrino-tasks/sql-helpers.rb
136
137
  - padrino-gen.gemspec
137
138
  - test/fixtures/admin_template.rb
138
139
  - test/fixtures/example_template.rb
@@ -176,9 +177,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
177
  - - ! '>='
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
- segments:
180
- - 0
181
- hash: -2733379671843302871
182
180
  required_rubygems_version: !ruby/object:Gem::Requirement
183
181
  none: false
184
182
  requirements: