lotusrb 0.4.1 → 0.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/FEATURES.md +7 -0
- data/README.md +2 -1
- data/lib/lotus/cli.rb +2 -1
- data/lib/lotus/commands/generate.rb +4 -0
- data/lib/lotus/config/assets.rb +46 -8
- data/lib/lotus/configuration.rb +119 -11
- data/lib/lotus/environment.rb +1 -1
- data/lib/lotus/frameworks.rb +2 -0
- data/lib/lotus/generators/action.rb +22 -1
- data/lib/lotus/generators/action/action_spec.rspec.tt +2 -3
- data/lib/lotus/generators/action/view_spec.rspec.tt +2 -3
- data/lib/lotus/generators/application/app.rb +22 -79
- data/lib/lotus/generators/application/app/Gemfile.tt +1 -0
- data/lib/lotus/generators/application/app/config/application.rb.tt +8 -3
- data/lib/lotus/generators/application/app/lib/app_name.rb.tt +12 -0
- data/lib/lotus/generators/application/container.rb +18 -84
- data/lib/lotus/generators/application/container/Gemfile.tt +3 -2
- data/lib/lotus/generators/application/container/lib/app_name.rb.tt +12 -0
- data/lib/lotus/generators/database_config.rb +86 -0
- data/lib/lotus/generators/mailer.rb +112 -0
- data/lib/lotus/generators/mailer/mailer.rb.tt +7 -0
- data/lib/lotus/generators/mailer/mailer_spec.rb.tt +7 -0
- data/lib/lotus/generators/mailer/template.html.tt +0 -0
- data/lib/lotus/generators/mailer/template.txt.tt +0 -0
- data/lib/lotus/generators/model/entity_spec.rspec.tt +0 -2
- data/lib/lotus/generators/model/repository_spec.rspec.tt +0 -2
- data/lib/lotus/generators/slice/application.rb.tt +8 -3
- data/lib/lotus/generators/slice/templates/application.html.erb.tt +1 -1
- data/lib/lotus/loader.rb +10 -3
- data/lib/lotus/mailer/glue.rb +68 -0
- data/lib/lotus/middleware.rb +3 -3
- data/lib/lotus/version.rb +1 -1
- data/lotusrb.gemspec +6 -5
- metadata +38 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7c8e5cd99a779eb8d3a481262d6af49538a457e
|
4
|
+
data.tar.gz: 5ea631568ee7e5fc205204e97c7d5daecaa8be5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed2204a15910591470fbb00e31331180a2192bbf0b9b4871a6b7fb5c2cdd9a043e53ecbb2193e32531f27ed5b14229118af90a7d441a69679cb156f6a5f2b0ab
|
7
|
+
data.tar.gz: e89361b9895b13d112f743e11ee83889be44561a6159429a24b9eb85c0297c20e9f8ed6e1ea386249776f094a6373417df5d7350e67351650a65f52022794523
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
# Lotus
|
2
2
|
A complete web framework for Ruby
|
3
3
|
|
4
|
+
## v0.5.0 - 2015-09-30
|
5
|
+
### Added
|
6
|
+
- [Ines Coelho & Rosa Faria] Mailers
|
7
|
+
- [Theo Felippe] Added configuration entries: `#default_request_format` and `default_response_format`
|
8
|
+
- [Rodrigo Panachi] Introduced `logger` configuration for applications, to be used like this: `Web::Logger.debug`
|
9
|
+
- [Ben Lovell] Simpler and less verbose RSpec tests
|
10
|
+
- [Pascal Betz] Introduced `--method` CLI argument for action generator as a way to specify the HTTP verb
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- [Luca Guidi] Handle conflicts between directories with the same name while serving static assets
|
14
|
+
- [Derk-Jan Karrenbeld] Include default value `font-src: self` for CSP HTTP header
|
15
|
+
- [Cam Huynh] Make CLI arguments immutable for `Lotus::Environment`
|
16
|
+
- [Andrii Ponomarov] Disable welcome page in test environment
|
17
|
+
- [Alfonso Uceda Pompa] Print error message and exit when no name is provided to model generator
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- [Theo Felippe] Deprecated `#default_format` in favor of: `#default_request_format`
|
21
|
+
|
4
22
|
## v0.4.1 - 2015-07-10
|
5
23
|
### Added
|
6
24
|
- [Trung Lê] Alias `--database` as `--db` for `lotus new`
|
data/FEATURES.md
CHANGED
data/README.md
CHANGED
@@ -8,8 +8,9 @@ Lotus combines small yet powerful frameworks:
|
|
8
8
|
|
9
9
|
* [**Lotus::Utils**](https://github.com/lotus/utils) - Ruby core extensions and class utilities
|
10
10
|
* [**Lotus::Router**](https://github.com/lotus/router) - Rack compatible HTTP router for Ruby
|
11
|
-
* [**Lotus::Validations**](https://github.com/lotus/validations) -
|
11
|
+
* [**Lotus::Validations**](https://github.com/lotus/validations) - Validations mixin for Ruby objects
|
12
12
|
* [**Lotus::Helpers**](https://github.com/lotus/helpers) - View helpers for Ruby applications
|
13
|
+
* [**Lotus::Mailer**](https://github.com/lotus/mailer) - Mail for Ruby applications
|
13
14
|
* [**Lotus::Model**](https://github.com/lotus/model) - Persistence with entities, repositories and data mapper
|
14
15
|
* [**Lotus::View**](https://github.com/lotus/view) - Presentation with a separation between views and templates
|
15
16
|
* [**Lotus::Controller**](https://github.com/lotus/controller) - Full featured, fast and testable actions for Rack
|
data/lib/lotus/cli.rb
CHANGED
@@ -79,10 +79,11 @@ module Lotus
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
desc 'generate', 'generates app, action, model or migration'
|
82
|
+
desc 'generate', 'generates app, action, model, mailer or migration'
|
83
83
|
method_option :application_base_url, desc: 'application base url', type: :string
|
84
84
|
method_option :path, desc: 'applications path', type: :string
|
85
85
|
method_option :url, desc: 'relative URL for action', type: :string
|
86
|
+
method_option :method, desc: "HTTP method for action. Upper/lower case is ignored. Must be one of GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE.", type: :string, default: 'GET'
|
86
87
|
method_option :skip_view, desc: 'skip the creation of view and templates (only for action)', type: :boolean, default: false
|
87
88
|
method_option :help, aliases: '-h', desc: 'displays the usage method'
|
88
89
|
|
data/lib/lotus/config/assets.rb
CHANGED
@@ -7,23 +7,60 @@ module Lotus
|
|
7
7
|
class Assets < Utils::LoadPaths
|
8
8
|
DEFAULT_DIRECTORY = 'public'.freeze
|
9
9
|
|
10
|
+
# Assets source (directory)
|
11
|
+
#
|
12
|
+
# @since 0.5.0
|
13
|
+
# @api private
|
14
|
+
class Source
|
15
|
+
# @since 0.5.0
|
16
|
+
# @api private
|
17
|
+
BLANK = ''.freeze
|
18
|
+
|
19
|
+
# @since 0.5.0
|
20
|
+
# @api private
|
21
|
+
URL_SEPARATOR = '/'.freeze
|
22
|
+
|
23
|
+
# @since 0.5.0
|
24
|
+
# @api private
|
25
|
+
attr_reader :urls
|
26
|
+
|
27
|
+
# @since 0.5.0
|
28
|
+
# @api private
|
29
|
+
attr_reader :root
|
30
|
+
|
31
|
+
# @since 0.5.0
|
32
|
+
# @api private
|
33
|
+
def initialize(path)
|
34
|
+
@path = path.to_s
|
35
|
+
@root = @path.sub("#{ Lotus.root }/", BLANK)
|
36
|
+
@urls = {}
|
37
|
+
|
38
|
+
Dir.glob("#{ path }/**/*").each do |file|
|
39
|
+
next if ::File.directory?(file)
|
40
|
+
|
41
|
+
@urls.store(
|
42
|
+
file.sub(@path, BLANK).sub(::File::SEPARATOR, URL_SEPARATOR),
|
43
|
+
file.sub("#{ @path }/", BLANK)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
@urls.freeze
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
10
51
|
# @since 0.1.0
|
11
52
|
# @api private
|
12
53
|
def initialize(root)
|
13
|
-
@root
|
54
|
+
@root = root
|
14
55
|
@paths = Array(DEFAULT_DIRECTORY)
|
15
56
|
end
|
16
57
|
|
17
|
-
# @since 0.
|
58
|
+
# @since 0.5.0
|
18
59
|
# @api private
|
19
|
-
def
|
20
|
-
hash = Hash.new { |k, v| k[v] = [] }
|
60
|
+
def for_each_source
|
21
61
|
each do |path|
|
22
|
-
if path.exist?
|
23
|
-
hash[path.to_s] = path.children.map { |child| "/#{ child.basename }" }
|
24
|
-
end
|
62
|
+
yield Source.new(path) if path.exist?
|
25
63
|
end
|
26
|
-
hash
|
27
64
|
end
|
28
65
|
|
29
66
|
# @since 0.2.0
|
@@ -41,3 +78,4 @@ module Lotus
|
|
41
78
|
end
|
42
79
|
end
|
43
80
|
end
|
81
|
+
|
data/lib/lotus/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'lotus/utils/kernel'
|
2
|
+
require 'lotus/utils/deprecation'
|
2
3
|
require 'lotus/environment'
|
3
4
|
require 'lotus/config/framework_configuration'
|
4
5
|
require 'lotus/config/load_paths'
|
@@ -958,18 +959,18 @@ module Lotus
|
|
958
959
|
# an argument, it will set the corresponding instance variable. When
|
959
960
|
# called without, it will return the already set value, or the default.
|
960
961
|
#
|
961
|
-
# @overload
|
962
|
+
# @overload default_request_format(format)
|
962
963
|
# Sets the given value
|
963
964
|
# @param format [#to_sym] the symbol format
|
964
965
|
# @raise [TypeError] if it cannot be coerced to a symbol
|
965
966
|
#
|
966
|
-
# @overload
|
967
|
+
# @overload default_request_format
|
967
968
|
# Gets the value
|
968
969
|
# @return [Symbol]
|
969
970
|
#
|
970
|
-
# @since 0.
|
971
|
+
# @since 0.5.0
|
971
972
|
#
|
972
|
-
# @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration#
|
973
|
+
# @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration#default_request_format
|
973
974
|
#
|
974
975
|
# @example Getting the value
|
975
976
|
# require 'lotus'
|
@@ -979,7 +980,7 @@ module Lotus
|
|
979
980
|
# end
|
980
981
|
# end
|
981
982
|
#
|
982
|
-
# Bookshelf::Application.configuration.
|
983
|
+
# Bookshelf::Application.configuration.default_request_format # => :html
|
983
984
|
#
|
984
985
|
# @example Setting the value
|
985
986
|
# require 'lotus'
|
@@ -987,20 +988,86 @@ module Lotus
|
|
987
988
|
# module Bookshelf
|
988
989
|
# class Application < Lotus::Application
|
989
990
|
# configure do
|
990
|
-
#
|
991
|
+
# default_request_format :json
|
991
992
|
# end
|
992
993
|
# end
|
993
994
|
# end
|
994
995
|
#
|
995
|
-
# Bookshelf::Application.configuration.
|
996
|
-
def
|
996
|
+
# Bookshelf::Application.configuration.default_request_format # => :json
|
997
|
+
def default_request_format(format = nil)
|
997
998
|
if format
|
998
|
-
@
|
999
|
+
@default_request_format = Utils::Kernel.Symbol(format)
|
999
1000
|
else
|
1000
|
-
@
|
1001
|
+
@default_request_format || :html
|
1001
1002
|
end
|
1002
1003
|
end
|
1003
1004
|
|
1005
|
+
# Set a format to be used for all responses regardless of the request type.
|
1006
|
+
#
|
1007
|
+
# The given format must be coercible to a symbol, and be a valid mime type
|
1008
|
+
# alias. If it isn't, at the runtime the framework will raise a
|
1009
|
+
# `Lotus::Controller::UnknownFormatError`.
|
1010
|
+
#
|
1011
|
+
# By default this value is `:html`.
|
1012
|
+
#
|
1013
|
+
# This is part of a DSL, for this reason when this method is called with
|
1014
|
+
# an argument, it will set the corresponding instance variable. When
|
1015
|
+
# called without, it will return the already set value, or the default.
|
1016
|
+
#
|
1017
|
+
# @overload default_response_format(format)
|
1018
|
+
# Sets the given value
|
1019
|
+
# @param format [#to_sym] the symbol format
|
1020
|
+
# @raise [TypeError] if it cannot be coerced to a symbol
|
1021
|
+
#
|
1022
|
+
# @overload default_response_format
|
1023
|
+
# Gets the value
|
1024
|
+
# @return [Symbol,nil]
|
1025
|
+
#
|
1026
|
+
# @since 0.5.0
|
1027
|
+
#
|
1028
|
+
# @see http://rdoc.info/gems/lotus-controller/Lotus/Controller/Configuration#default_response_format
|
1029
|
+
#
|
1030
|
+
# @example Getting the value
|
1031
|
+
# require 'lotus'
|
1032
|
+
#
|
1033
|
+
# module Bookshelf
|
1034
|
+
# class Application < Lotus::Application
|
1035
|
+
# end
|
1036
|
+
# end
|
1037
|
+
#
|
1038
|
+
# Bookshelf::Application.configuration.default_response_format # => :html
|
1039
|
+
#
|
1040
|
+
# @example Setting the value
|
1041
|
+
# require 'lotus'
|
1042
|
+
#
|
1043
|
+
# module Bookshelf
|
1044
|
+
# class Application < Lotus::Application
|
1045
|
+
# configure do
|
1046
|
+
# default_response_format :json
|
1047
|
+
# end
|
1048
|
+
# end
|
1049
|
+
# end
|
1050
|
+
#
|
1051
|
+
# Bookshelf::Application.configuration.default_response_format # => :json
|
1052
|
+
def default_response_format(format = nil)
|
1053
|
+
if format
|
1054
|
+
@default_response_format = Utils::Kernel.Symbol(format)
|
1055
|
+
else
|
1056
|
+
@default_response_format
|
1057
|
+
end
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
# Set a format as default fallback for all the requests without a strict
|
1061
|
+
# requirement for the mime type.
|
1062
|
+
#
|
1063
|
+
# @since 0.1.0
|
1064
|
+
#
|
1065
|
+
# @deprecated Use {#default_request_format} instead.
|
1066
|
+
def default_format(format = nil)
|
1067
|
+
Lotus::Utils::Deprecation.new('default_format is deprecated, please use default_request_format')
|
1068
|
+
default_request_format(format)
|
1069
|
+
end
|
1070
|
+
|
1004
1071
|
# The URI scheme for this application.
|
1005
1072
|
# This is used by the router helpers to generate absolute URLs.
|
1006
1073
|
#
|
@@ -1577,7 +1644,7 @@ module Lotus
|
|
1577
1644
|
# module Bookshelf
|
1578
1645
|
# class Application < Lotus::Application
|
1579
1646
|
# configure do
|
1580
|
-
# controller.
|
1647
|
+
# controller.default_request_format :json
|
1581
1648
|
# end
|
1582
1649
|
# end
|
1583
1650
|
# end
|
@@ -1642,6 +1709,46 @@ module Lotus
|
|
1642
1709
|
@view ||= Config::FrameworkConfiguration.new
|
1643
1710
|
end
|
1644
1711
|
|
1712
|
+
# Defines a logger instance to the configuration
|
1713
|
+
#
|
1714
|
+
# This logger instance will be used to set the logger available on application module
|
1715
|
+
#
|
1716
|
+
# If no logger instance is defined, a Lotus::Logger will be set by default
|
1717
|
+
#
|
1718
|
+
# @return [Logger, NilClass] logger instance
|
1719
|
+
#
|
1720
|
+
# @since 0.5.0
|
1721
|
+
#
|
1722
|
+
# @example Define a logger
|
1723
|
+
# require 'lotus'
|
1724
|
+
#
|
1725
|
+
# module Bookshelf
|
1726
|
+
# class Application < Lotus::Application
|
1727
|
+
# configure do
|
1728
|
+
# logger Logger.new(STDOUT)
|
1729
|
+
# end
|
1730
|
+
# load!
|
1731
|
+
# end
|
1732
|
+
#
|
1733
|
+
# module Controllers::Error
|
1734
|
+
# include Bookshelf::Controller
|
1735
|
+
#
|
1736
|
+
# action 'Index' do
|
1737
|
+
# def call(params)
|
1738
|
+
# Bookshelf::Logger.info "Logging to STDOUT"
|
1739
|
+
# end
|
1740
|
+
# end
|
1741
|
+
# end
|
1742
|
+
# end
|
1743
|
+
#
|
1744
|
+
def logger(value = nil)
|
1745
|
+
if value.nil?
|
1746
|
+
@logger
|
1747
|
+
else
|
1748
|
+
@logger = value
|
1749
|
+
end
|
1750
|
+
end
|
1751
|
+
|
1645
1752
|
# This options is used as a bridge between container and router application.
|
1646
1753
|
#
|
1647
1754
|
# @return [String, NilClass] path prefix for routes
|
@@ -1657,6 +1764,7 @@ module Lotus
|
|
1657
1764
|
end
|
1658
1765
|
|
1659
1766
|
private
|
1767
|
+
|
1660
1768
|
# @since 0.2.0
|
1661
1769
|
# @api private
|
1662
1770
|
def evaluate_configurations!
|
data/lib/lotus/environment.rb
CHANGED
@@ -174,7 +174,7 @@ module Lotus
|
|
174
174
|
# # other settings (eg `XYZ`) will be left untouched.
|
175
175
|
def initialize(options = {})
|
176
176
|
@options = Lotus::Lotusrc.new(root, options).read
|
177
|
-
@options.merge! Utils::Hash.new(options).symbolize!
|
177
|
+
@options.merge! Utils::Hash.new(options.clone).symbolize!
|
178
178
|
@mutex = Mutex.new
|
179
179
|
@mutex.synchronize { set_env_vars! }
|
180
180
|
end
|
data/lib/lotus/frameworks.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'lotus/generators/abstract'
|
2
2
|
require 'lotus/utils/string'
|
3
|
+
require 'lotus/routing/route'
|
3
4
|
|
4
5
|
module Lotus
|
5
6
|
module Generators
|
@@ -30,6 +31,11 @@ module Lotus
|
|
30
31
|
# @api private
|
31
32
|
DEFAULT_TEMPLATE = 'erb'.freeze
|
32
33
|
|
34
|
+
# Default HTTP method used when generating an action.
|
35
|
+
# @since 0.5.0
|
36
|
+
# @api private
|
37
|
+
DEFAULT_HTTP_METHOD = 'GET'.freeze
|
38
|
+
|
33
39
|
# @since 0.3.0
|
34
40
|
# @api private
|
35
41
|
def initialize(command)
|
@@ -48,6 +54,7 @@ module Lotus
|
|
48
54
|
def start
|
49
55
|
assert_existing_app!
|
50
56
|
assert_action!
|
57
|
+
assert_http_method!
|
51
58
|
|
52
59
|
opts = {
|
53
60
|
app: app,
|
@@ -108,6 +115,14 @@ module Lotus
|
|
108
115
|
end
|
109
116
|
end
|
110
117
|
|
118
|
+
# @since 0.5.0
|
119
|
+
# @api private
|
120
|
+
def assert_http_method!
|
121
|
+
if !Lotus::Routing::Route::VALID_HTTP_VERBS.include?(_http_method.upcase)
|
122
|
+
raise Lotus::Commands::Generate::Error.new("Unknown HTTP method '#{_http_method}', please use one of #{Lotus::Routing::Route::VALID_HTTP_VERBS.join(', ')}.")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
111
126
|
def app
|
112
127
|
if env.container?
|
113
128
|
super
|
@@ -127,10 +142,16 @@ module Lotus
|
|
127
142
|
|
128
143
|
# Insert at the top of the file
|
129
144
|
cli.insert_into_file _routes_path, before: /\A(.*)/ do
|
130
|
-
"
|
145
|
+
"#{ _http_method } '#{ _route_url }', to: '#{ _route_endpoint }'\n"
|
131
146
|
end
|
132
147
|
end
|
133
148
|
|
149
|
+
# @since 0.5.0
|
150
|
+
# @api private
|
151
|
+
def _http_method
|
152
|
+
options.fetch(:method, DEFAULT_HTTP_METHOD).downcase
|
153
|
+
end
|
154
|
+
|
134
155
|
# @since 0.4.0
|
135
156
|
# @api private
|
136
157
|
def _route_url
|
@@ -1,11 +1,10 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require_relative '<%= config[:relative_action_path] %>'
|
3
2
|
|
4
3
|
describe <%= config[:app] %>::Controllers::<%= config[:controller] %>::<%= config[:action] %> do
|
5
|
-
let(:action) {
|
4
|
+
let(:action) { described_class.new }
|
6
5
|
let(:params) { Hash[] }
|
7
6
|
|
8
|
-
it
|
7
|
+
it 'is successful' do
|
9
8
|
response = action.call(params)
|
10
9
|
expect(response[0]).to eq 200
|
11
10
|
end
|