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,90 +0,0 @@
1
- require 'lotus/generators/abstract'
2
- require 'lotus/utils/string'
3
-
4
- module Lotus
5
- module Generators
6
- class Model < Abstract
7
-
8
- # @since 0.3.1
9
- # @api private
10
- def initialize(command)
11
- super
12
-
13
- @model_name = Utils::String.new(name).classify
14
- cli.class.source_root(source)
15
- end
16
-
17
- # @since 0.3.1
18
- # @api private
19
- def start
20
- assert_model!
21
-
22
- opts = {
23
- model_name: @model_name
24
- }
25
-
26
- templates = {
27
- 'entity.rb.tt' => _entity_path,
28
- 'repository.rb.tt' => _repository_path
29
- }
30
-
31
- case options[:test]
32
- when 'rspec'
33
- templates.merge!({
34
- 'entity_spec.rspec.tt' => _entity_spec_path,
35
- 'repository_spec.rspec.tt' => _repository_spec_path,
36
- })
37
- else
38
- templates.merge!({
39
- 'entity_spec.minitest.tt' => _entity_spec_path,
40
- 'repository_spec.minitest.tt' => _repository_spec_path,
41
- })
42
- end
43
-
44
- templates.each do |src, dst|
45
- cli.template(source.join(src), target.join(dst), opts)
46
- end
47
- end
48
-
49
- private
50
- # @since 0.3.1
51
- # @api private
52
- def _entity_path
53
- model_root.join("entities", "#{ name }.rb").to_s
54
- end
55
-
56
- # @since 0.3.1
57
- # @api private
58
- def _repository_path
59
- model_root.join("repositories", "#{ name }_repository.rb").to_s
60
- end
61
-
62
- # @since 0.3.1
63
- # @api private
64
- def _entity_spec_path
65
- spec_root.join(::File.basename(Dir.getwd), 'entities', "#{ name }_spec.rb")
66
- end
67
-
68
- # @since 0.3.1
69
- # @api private
70
- def _repository_spec_path
71
- spec_root.join(::File.basename(Dir.getwd), 'repositories',
72
- "#{ name }_repository_spec.rb")
73
- end
74
-
75
- # @since 0.4.0
76
- # @api private
77
- def name
78
- Utils::String.new(app_name || super).underscore
79
- end
80
-
81
- # @since 0.4.1
82
- # @api private
83
- def assert_model!
84
- if @model_name.nil? || @model_name.empty?
85
- raise Lotus::Commands::Generate::Error.new("Missing model name")
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,94 +0,0 @@
1
- require 'securerandom'
2
- require 'lotus/generators/abstract'
3
- require 'lotus/utils/string'
4
- require 'lotus/application_name'
5
-
6
- module Lotus
7
- module Generators
8
- class Slice < Abstract
9
- def initialize(command)
10
- super
11
-
12
- application_name = ApplicationName.new(options.fetch(:application))
13
- @slice_name = application_name.to_s
14
- @upcase_slice_name = application_name.to_env_s
15
- @classified_slice_name = Utils::String.new(@slice_name).classify
16
-
17
- @source = Pathname.new(::File.dirname(__FILE__) + '/../generators/slice')
18
- @target = target.join('apps', @slice_name)
19
-
20
- @slice_base_url = options.fetch(:application_base_url)
21
-
22
- cli.class.source_root(@source)
23
- end
24
-
25
- def start
26
- opts = {
27
- slice_name: @slice_name,
28
- upcase_slice_name: @upcase_slice_name,
29
- classified_slice_name: @classified_slice_name,
30
- slice_base_url: @slice_base_url
31
- }
32
-
33
- templates = {
34
- 'application.rb.tt' => 'application.rb',
35
- 'config/routes.rb.tt' => 'config/routes.rb',
36
- 'views/application_layout.rb.tt' => 'views/application_layout.rb',
37
- 'templates/application.html.erb.tt' => 'templates/application.html.erb',
38
- }
39
-
40
- empty_directories = [
41
- 'controllers',
42
- 'public/javascripts',
43
- 'public/stylesheets'
44
- ]
45
-
46
- # Add testing directories (spec/ is the default for both MiniTest and RSpec)
47
- empty_directories << [
48
- "../../spec/#{ opts[:slice_name] }/features",
49
- "../../spec/#{ opts[:slice_name] }/controllers",
50
- "../../spec/#{ opts[:slice_name] }/views"
51
- ]
52
-
53
- ##
54
- # config/environment.rb
55
- #
56
-
57
- # Add "require_relative '../apps/web/application'"
58
- cli.inject_into_file target.join('config/environment.rb'), after: /require_relative '\.\.\/lib\/(.*)'/ do
59
- "\nrequire_relative '../apps/#{ opts[:slice_name] }/application'"
60
- end
61
-
62
- # Mount slice inside "Lotus::Container.configure"
63
- cli.inject_into_file target.join('config/environment.rb'), after: /Lotus::Container.configure do/ do |match|
64
- "\n mount #{ opts[:classified_slice_name] }::Application, at: '#{ opts[:slice_base_url] }'"
65
- end
66
-
67
- ##
68
- # Per environment .env
69
- #
70
- ['development', 'test'].each do |environment|
71
- # Add WEB_SESSIONS_SECRET="abc123" (random hex)
72
- cli.append_to_file target.join(".env.#{ environment }") do
73
- %(#{ opts[:upcase_slice_name] }_SESSIONS_SECRET="#{ SecureRandom.hex(32) }"\n)
74
- end
75
- end
76
-
77
- ##
78
- # New files
79
- #
80
- templates.each do |src, dst|
81
- cli.template(@source.join(src), @target.join(dst), opts)
82
- end
83
-
84
- ##
85
- # Empty directories
86
- #
87
- empty_directories.flatten.each do |dir|
88
- gitkeep = '.gitkeep'
89
- cli.template(@source.join(gitkeep), @target.join(dir, gitkeep), opts)
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,7 +0,0 @@
1
- module <%= config[:classified_slice_name] %>
2
- module Views
3
- class ApplicationLayout
4
- include <%= config[:classified_slice_name] %>::Layout
5
- end
6
- end
7
- end