lotusrb 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -14
  3. data/FEATURES.md +21 -0
  4. data/LICENSE.md +1 -1
  5. data/README.md +8 -7
  6. data/bin/lotus +1 -0
  7. data/lib/lotus.rb +6 -0
  8. data/lib/lotus/action/csrf_protection.rb +1 -1
  9. data/lib/lotus/application.rb +4 -4
  10. data/lib/lotus/application_name.rb +8 -6
  11. data/lib/lotus/cli.rb +75 -66
  12. data/lib/lotus/cli_sub_commands/assets.rb +29 -0
  13. data/lib/lotus/{commands → cli_sub_commands}/db.rb +24 -29
  14. data/lib/lotus/cli_sub_commands/destroy.rb +102 -0
  15. data/lib/lotus/cli_sub_commands/generate.rb +127 -0
  16. data/lib/lotus/commands/assets/precompile.rb +35 -0
  17. data/lib/lotus/commands/console.rb +28 -8
  18. data/lib/lotus/commands/db/abstract.rb +6 -2
  19. data/lib/lotus/commands/db/console.rb +5 -5
  20. data/lib/lotus/commands/generate/abstract.rb +63 -0
  21. data/lib/lotus/commands/generate/action.rb +262 -0
  22. data/lib/lotus/commands/generate/app.rb +116 -0
  23. data/lib/lotus/commands/generate/mailer.rb +118 -0
  24. data/lib/lotus/commands/generate/migration.rb +63 -0
  25. data/lib/lotus/commands/generate/model.rb +96 -0
  26. data/lib/lotus/commands/new/abstract.rb +128 -0
  27. data/lib/lotus/commands/new/app.rb +116 -0
  28. data/lib/lotus/commands/new/container.rb +102 -0
  29. data/lib/lotus/commands/routes.rb +19 -2
  30. data/lib/lotus/commands/server.rb +16 -2
  31. data/lib/lotus/config/framework_configuration.rb +13 -1
  32. data/lib/lotus/configuration.rb +24 -76
  33. data/lib/lotus/container.rb +15 -2
  34. data/lib/lotus/environment.rb +43 -4
  35. data/lib/lotus/frameworks.rb +1 -0
  36. data/lib/lotus/generators/action/action_spec.minitest.tt +1 -1
  37. data/lib/lotus/generators/action/action_spec.rspec.tt +1 -1
  38. data/lib/lotus/generators/action/view_spec.minitest.tt +1 -1
  39. data/lib/lotus/generators/action/view_spec.rspec.tt +1 -1
  40. data/lib/lotus/generators/{slice → app}/.gitkeep.tt +0 -0
  41. data/lib/lotus/generators/{slice → app}/application.rb.tt +61 -23
  42. data/lib/lotus/generators/app/config/initializers/.gitkeep +0 -0
  43. data/lib/lotus/generators/{slice → app}/config/routes.rb.tt +0 -0
  44. data/lib/lotus/generators/app/favicon.ico +0 -0
  45. data/lib/lotus/generators/{slice → app}/templates/application.html.erb.tt +2 -1
  46. data/lib/lotus/generators/app/views/application_layout.rb.tt +7 -0
  47. data/lib/lotus/generators/application/app/.env.development.tt +1 -0
  48. data/lib/lotus/generators/application/app/.env.test.tt +1 -0
  49. data/lib/lotus/generators/application/app/Gemfile.tt +1 -0
  50. data/lib/lotus/generators/application/app/Rakefile.minitest.tt +1 -0
  51. data/lib/lotus/generators/application/app/Rakefile.rspec.tt +1 -0
  52. data/lib/lotus/generators/application/app/config/application.rb.tt +56 -18
  53. data/lib/lotus/generators/application/app/config/initializers/.gitkeep +0 -0
  54. data/lib/lotus/generators/application/app/favicon.ico +0 -0
  55. data/lib/lotus/generators/application/app/gitignore.tt +2 -0
  56. data/lib/lotus/generators/application/app/lotusrc.tt +3 -3
  57. data/lib/lotus/generators/application/app/spec_helper.rb.rspec.tt +5 -1
  58. data/lib/lotus/generators/application/app/templates/application.html.erb.tt +1 -0
  59. data/lib/lotus/generators/application/container/.env.development.tt +1 -0
  60. data/lib/lotus/generators/application/container/.env.test.tt +1 -0
  61. data/lib/lotus/generators/application/container/Gemfile.tt +1 -1
  62. data/lib/lotus/generators/application/container/Rakefile.minitest.tt +1 -0
  63. data/lib/lotus/generators/application/container/Rakefile.rspec.tt +1 -0
  64. data/lib/lotus/generators/application/container/config/initializers/.gitkeep +0 -0
  65. data/lib/lotus/generators/application/container/gitignore.tt +2 -0
  66. data/lib/lotus/generators/application/container/lib/chirp/mailers/.gitkeep +0 -0
  67. data/lib/lotus/generators/application/container/lib/chirp/mailers/templates/.gitkeep +0 -0
  68. data/lib/lotus/generators/application/container/lotusrc.tt +3 -3
  69. data/lib/lotus/generators/application/container/spec_helper.rb.rspec.tt +5 -1
  70. data/lib/lotus/generators/database_config.rb +17 -4
  71. data/lib/lotus/generators/generatable.rb +51 -0
  72. data/lib/lotus/generators/generator.rb +35 -0
  73. data/lib/lotus/generators/test_framework.rb +42 -0
  74. data/lib/lotus/loader.rb +43 -0
  75. data/lib/lotus/lotusrc.rb +50 -49
  76. data/lib/lotus/middleware.rb +28 -10
  77. data/lib/lotus/rake_helper.rb +68 -0
  78. data/lib/lotus/rake_tasks.rb +2 -0
  79. data/lib/lotus/rendering_policy.rb +2 -2
  80. data/lib/lotus/repositories/car_repository.rb +3 -0
  81. data/lib/lotus/repositories/name_repository.rb +3 -0
  82. data/lib/lotus/setup.rb +1 -3
  83. data/lib/lotus/static.rb +77 -0
  84. data/lib/lotus/templates/welcome.html.erb +7 -4
  85. data/lib/lotus/version.rb +1 -1
  86. data/lib/lotus/views/default.rb +2 -1
  87. data/lib/lotus/views/default_template_finder.rb +4 -3
  88. data/lotusrb.gemspec +11 -9
  89. metadata +79 -60
  90. data/lib/lotus/commands/generate.rb +0 -97
  91. data/lib/lotus/commands/new.rb +0 -43
  92. data/lib/lotus/config/assets.rb +0 -81
  93. data/lib/lotus/generators/abstract.rb +0 -31
  94. data/lib/lotus/generators/action.rb +0 -235
  95. data/lib/lotus/generators/app.rb +0 -39
  96. data/lib/lotus/generators/app/.gitkeep +0 -1
  97. data/lib/lotus/generators/application/app.rb +0 -129
  98. data/lib/lotus/generators/application/container.rb +0 -111
  99. data/lib/lotus/generators/mailer.rb +0 -112
  100. data/lib/lotus/generators/migration.rb +0 -58
  101. data/lib/lotus/generators/model.rb +0 -90
  102. data/lib/lotus/generators/slice.rb +0 -94
  103. data/lib/lotus/generators/slice/views/application_layout.rb.tt +0 -7
@@ -1,39 +0,0 @@
1
- require 'shellwords'
2
- require 'lotus/generators/abstract'
3
- require 'lotus/generators/slice'
4
-
5
- module Lotus
6
- module Generators
7
- class App < Abstract
8
- def initialize(command)
9
- super
10
-
11
- options.merge!(app_name_options)
12
- @slice_generator = Slice.new(command)
13
-
14
- cli.class.source_root(source)
15
- end
16
-
17
- def start
18
- @slice_generator.start
19
- end
20
-
21
- private
22
-
23
- # @since 0.4.0
24
- # @api private
25
- def app_name_options
26
- {
27
- application: app_name,
28
- application_base_url: application_base_url
29
- }
30
- end
31
-
32
- # @since 0.4.0
33
- # @api private
34
- def application_base_url
35
- options[:application_base_url] || "/#{app_name}"
36
- end
37
- end
38
- end
39
- end
@@ -1 +0,0 @@
1
- #
@@ -1,129 +0,0 @@
1
- require 'shellwords'
2
- require 'lotus/generators/abstract'
3
- require 'lotus/generators/database_config'
4
-
5
- module Lotus
6
- module Generators
7
- module Application
8
- class App < Abstract
9
- def initialize(command)
10
- super
11
-
12
- @upcase_app_name = app_name.to_env_s
13
- @classified_app_name = Utils::String.new(app_name).classify
14
- @lotus_head = options.fetch(:lotus_head)
15
- @test = options[:test]
16
- @database_config = DatabaseConfig.new(options[:database], app_name)
17
- @application_base_url = options[:application_base_url]
18
- @lotus_model_version = '~> 0.5'
19
-
20
- cli.class.source_root(source)
21
- end
22
-
23
- def start
24
-
25
- opts = {
26
- app_name: app_name,
27
- upcase_app_name: @upcase_app_name,
28
- classified_app_name: @classified_app_name,
29
- application_base_url: @application_base_url,
30
- lotus_head: @lotus_head,
31
- test: @test,
32
- database: @database_config.engine,
33
- database_config: @database_config.to_hash,
34
- lotus_model_version: @lotus_model_version,
35
- }
36
-
37
- templates = {
38
- 'lotusrc.tt' => '.lotusrc',
39
- '.env.tt' => '.env',
40
- '.env.development.tt' => '.env.development',
41
- '.env.test.tt' => '.env.test',
42
- 'Gemfile.tt' => 'Gemfile',
43
- 'config.ru.tt' => 'config.ru',
44
- 'config/environment.rb.tt' => 'config/environment.rb',
45
- 'lib/app_name.rb.tt' => "lib/#{ app_name }.rb",
46
- 'lib/config/mapping.rb.tt' => 'lib/config/mapping.rb',
47
- 'config/application.rb.tt' => 'config/application.rb',
48
- 'config/routes.rb.tt' => 'config/routes.rb',
49
- 'views/application_layout.rb.tt' => 'app/views/application_layout.rb',
50
- 'templates/application.html.erb.tt' => 'app/templates/application.html.erb',
51
- }
52
-
53
- empty_directories = [
54
- "app/controllers",
55
- "app/views",
56
- "lib/#{ app_name }/entities",
57
- "lib/#{ app_name }/repositories",
58
- "lib/#{ app_name }/mailers",
59
- "public/javascripts",
60
- "public/stylesheets"
61
- ]
62
-
63
- empty_directories << if @database_config.sql?
64
- "db/migrations"
65
- else
66
- "db"
67
- end
68
-
69
- # Add testing directories (spec/ is the default for both MiniTest and RSpec)
70
- empty_directories << [
71
- "spec/features",
72
- "spec/controllers",
73
- "spec/views"
74
- ]
75
-
76
- case options[:test]
77
- when 'rspec'
78
- templates.merge!(
79
- 'Rakefile.rspec.tt' => 'Rakefile',
80
- 'rspec.rspec.tt' => '.rspec',
81
- 'spec_helper.rb.rspec.tt' => 'spec/spec_helper.rb',
82
- 'features_helper.rb.rspec.tt' => 'spec/features_helper.rb',
83
- 'capybara.rb.rspec.tt' => 'spec/support/capybara.rb'
84
- )
85
- else # minitest (default)
86
- templates.merge!(
87
- 'Rakefile.minitest.tt' => 'Rakefile',
88
- 'spec_helper.rb.minitest.tt' => 'spec/spec_helper.rb',
89
- 'features_helper.rb.minitest.tt' => 'spec/features_helper.rb'
90
- )
91
- end
92
-
93
- empty_directories << [
94
- "spec/#{ app_name }/entities",
95
- "spec/#{ app_name }/repositories",
96
- "spec/#{ app_name }/mailers",
97
- "spec/support"
98
- ]
99
-
100
- if @database_config.sql?
101
- templates.merge!(
102
- 'schema.sql.tt' => 'db/schema.sql'
103
- )
104
- end
105
-
106
- templates.each do |src, dst|
107
- cli.template(source.join(src), target.join(dst), opts)
108
- end
109
-
110
- empty_directories.flatten.each do |dir|
111
- gitkeep = '.gitkeep'
112
- cli.template(source.join(gitkeep), target.join(dir, gitkeep), opts)
113
- end
114
-
115
- unless git_dir_present?
116
- cli.template(source.join(@database_config.type == :file_system ? 'gitignore.tt' : '.gitignore'), target.join('.gitignore'), opts)
117
- cli.run("git init #{Shellwords.escape(target)}", capture: true)
118
- end
119
- end
120
-
121
- private
122
-
123
- def git_dir_present?
124
- File.directory?(source.join('.git'))
125
- end
126
- end
127
- end
128
- end
129
- end
@@ -1,111 +0,0 @@
1
- require 'shellwords'
2
- require 'lotus/generators/abstract'
3
- require 'lotus/generators/database_config'
4
- require 'lotus/generators/slice'
5
-
6
- module Lotus
7
- module Generators
8
- module Application
9
- class Container < Abstract
10
- def initialize(command)
11
- super
12
-
13
- @slice_generator = Slice.new(command)
14
- @database_config = DatabaseConfig.new(options[:database], app_name)
15
- @lotus_head = options.fetch(:lotus_head)
16
- @test = options[:test]
17
- @lotus_model_version = '~> 0.5'
18
-
19
- cli.class.source_root(source)
20
- end
21
-
22
- def start
23
- opts = {
24
- app_name: app_name,
25
- lotus_head: @lotus_head,
26
- test: @test,
27
- database: @database_config.engine,
28
- database_config: @database_config.to_hash,
29
- lotus_model_version: @lotus_model_version,
30
- }
31
-
32
- templates = {
33
- 'lotusrc.tt' => '.lotusrc',
34
- '.env.tt' => '.env',
35
- '.env.development.tt' => '.env.development',
36
- '.env.test.tt' => '.env.test',
37
- 'Gemfile.tt' => 'Gemfile',
38
- 'config.ru.tt' => 'config.ru',
39
- 'config/environment.rb.tt' => 'config/environment.rb',
40
- 'lib/app_name.rb.tt' => "lib/#{ app_name }.rb",
41
- 'lib/config/mapping.rb.tt' => 'lib/config/mapping.rb',
42
- }
43
-
44
- empty_directories = [
45
- "lib/#{ app_name }/entities",
46
- "lib/#{ app_name }/repositories",
47
- "lib/#{ app_name }/mailers"
48
- ]
49
-
50
- empty_directories << if @database_config.sql?
51
- "db/migrations"
52
- else
53
- "db"
54
- end
55
-
56
- case options[:test]
57
- when 'rspec'
58
- templates.merge!(
59
- 'Rakefile.rspec.tt' => 'Rakefile',
60
- 'rspec.rspec.tt' => '.rspec',
61
- 'spec_helper.rb.rspec.tt' => 'spec/spec_helper.rb',
62
- 'features_helper.rb.rspec.tt' => 'spec/features_helper.rb',
63
- 'capybara.rb.rspec.tt' => 'spec/support/capybara.rb'
64
- )
65
- else # minitest (default)
66
- templates.merge!(
67
- 'Rakefile.minitest.tt' => 'Rakefile',
68
- 'spec_helper.rb.minitest.tt' => 'spec/spec_helper.rb',
69
- 'features_helper.rb.minitest.tt' => 'spec/features_helper.rb'
70
- )
71
- end
72
-
73
- if @database_config.sql?
74
- templates.merge!(
75
- 'schema.sql.tt' => 'db/schema.sql'
76
- )
77
- end
78
-
79
- empty_directories << [
80
- "spec/#{ app_name }/entities",
81
- "spec/#{ app_name }/repositories",
82
- "spec/#{ app_name }/mailers",
83
- "spec/support"
84
- ]
85
-
86
- templates.each do |src, dst|
87
- cli.template(source.join(src), target.join(dst), opts)
88
- end
89
-
90
- empty_directories.flatten.each do |dir|
91
- gitkeep = '.gitkeep'
92
- cli.template(source.join(gitkeep), target.join(dir, gitkeep), opts)
93
- end
94
-
95
- unless git_dir_present?
96
- cli.template(source.join(@database_config.type == :file_system ? 'gitignore.tt' : '.gitignore'), target.join('.gitignore'), opts)
97
- cli.run("git init #{Shellwords.escape(target)}", capture: true)
98
- end
99
-
100
- @slice_generator.start
101
- end
102
-
103
- private
104
-
105
- def git_dir_present?
106
- File.directory?(source.join('.git'))
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,112 +0,0 @@
1
- require 'lotus/generators/abstract'
2
- require 'lotus/utils/string'
3
-
4
- module Lotus
5
- module Generators
6
- # @since 0.5.0
7
- # @api private
8
- class Mailer < Abstract
9
-
10
- # @since 0.5.0
11
- # @api private
12
- TXT_FORMAT = '.txt'.freeze
13
-
14
- # @since 0.5.0
15
- # @api private
16
- HTML_FORMAT = '.html'.freeze
17
-
18
- # @since 0.5.0
19
- # @api private
20
- DEFAULT_ENGINE = 'erb'.freeze
21
-
22
- # @since 0.5.0
23
- # @api private
24
- DEFAULT_FROM = "'<from>'".freeze
25
-
26
- # @since 0.5.0
27
- # @api private
28
- DEFAULT_TO = "'<to>'".freeze
29
-
30
- # @since 0.5.0
31
- # @api private
32
- DEFAULT_SUBJECT = "'Hello'".freeze
33
-
34
- # @since 0.5.0
35
- # @api private
36
- def initialize(command)
37
- super
38
-
39
- @mailer_name = Utils::String.new(name).classify
40
- cli.class.source_root(source)
41
- end
42
-
43
- # @since 0.5.0
44
- # @api private
45
- def start
46
- assert_mailer!
47
-
48
- opts = {
49
- mailer: @mailer_name,
50
- from: DEFAULT_FROM,
51
- to: DEFAULT_TO,
52
- subject: DEFAULT_SUBJECT,
53
- }
54
-
55
- templates = {
56
- 'mailer_spec.rb.tt' => _mailer_spec_path,
57
- 'mailer.rb.tt' => _mailer_path,
58
- 'template.txt.tt' => _txt_template_path,
59
- 'template.html.tt' => _html_template_path,
60
- }
61
-
62
- templates.each do |src, dst|
63
- cli.template(source.join(src), target.join(dst), opts)
64
- end
65
- end
66
-
67
- # @since 0.5.0
68
- # @api private
69
- def assert_mailer!
70
- if @mailer_name.nil? || @mailer_name.empty?
71
- raise Lotus::Commands::Generate::Error.new("Missing mailer name")
72
- end
73
- end
74
-
75
- # @since 0.5.0
76
- # @api private
77
- def _mailer_path
78
- core_root.join('mailers', "#{ name }.rb").to_s
79
- end
80
-
81
- # @since 0.5.0
82
- # @api private
83
- def _mailer_spec_path
84
- spec_root.join(::File.basename(Dir.getwd), 'mailers', "#{ name }_spec.rb")
85
- end
86
-
87
- # @since 0.5.0
88
- # @api private
89
- def _txt_template_path
90
- __template_path(TXT_FORMAT)
91
- end
92
-
93
- # @since 0.5.0
94
- # @api private
95
- def _html_template_path
96
- __template_path(HTML_FORMAT)
97
- end
98
-
99
- # @since 0.5.0
100
- # @api private
101
- def __template_path(format)
102
- core_root.join('mailers', 'templates', "#{ name }#{ format }.#{ DEFAULT_ENGINE }")
103
- end
104
-
105
- # @since 0.5.0
106
- # @api private
107
- def name
108
- Utils::String.new(app_name || super).underscore
109
- end
110
- end
111
- end
112
- end
@@ -1,58 +0,0 @@
1
- require 'lotus/generators/abstract'
2
- require 'lotus/utils/string'
3
-
4
- module Lotus
5
- module Generators
6
- # @since 0.4.0
7
- # @api private
8
- class Migration < Abstract
9
- # @since 0.4.0
10
- # @api private
11
- #
12
- # @example
13
- # 20150612160502
14
- TIMESTAMP_FORMAT = '%Y%m%d%H%M%S'.freeze
15
-
16
- # @since 0.4.0
17
- # @api private
18
- #
19
- # @example
20
- # 20150612160502_create_books.rb
21
- FILENAME = '%{timestamp}_%{name}.rb'.freeze
22
-
23
- # @since 0.4.0
24
- # @api private
25
- def initialize(command)
26
- super
27
-
28
- timestamp = Time.now.utc.strftime(TIMESTAMP_FORMAT)
29
- filename = FILENAME % { timestamp: timestamp, name: name }
30
-
31
- env.require_application_environment
32
- @destination = Lotus::Model.configuration.migrations.join(filename)
33
-
34
- cli.class.source_root(source)
35
- end
36
-
37
- # @since 0.4.0
38
- # @api private
39
- def start
40
- templates = {
41
- 'migration.rb.tt' => @destination
42
- }
43
-
44
- templates.each do |src, dst|
45
- cli.template(source.join(src), target.join(dst), {})
46
- end
47
- end
48
-
49
- private
50
-
51
- # @since 0.4.0
52
- # @api private
53
- def name
54
- Utils::String.new(app_name || super).underscore
55
- end
56
- end
57
- end
58
- end