wallaby-core 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -13
  3. data/app/controllers/wallaby/application_controller.rb +6 -6
  4. data/app/controllers/wallaby/resources_controller.rb +4 -3
  5. data/app/controllers/wallaby/secure_controller.rb +2 -2
  6. data/lib/concerns/wallaby/authorizable.rb +0 -6
  7. data/lib/concerns/wallaby/prefixable.rb +21 -0
  8. data/lib/concerns/wallaby/servicable.rb +0 -6
  9. data/lib/helpers/wallaby/application_helper.rb +0 -9
  10. data/lib/helpers/wallaby/form_helper.rb +0 -6
  11. data/lib/helpers/wallaby/index_helper.rb +0 -12
  12. data/lib/helpers/wallaby/resources_helper.rb +0 -7
  13. data/lib/parsers/wallaby/parser.rb +49 -14
  14. data/lib/services/wallaby/prefixes_builder.rb +15 -49
  15. data/lib/services/wallaby/type_renderer.rb +1 -1
  16. data/lib/utils/wallaby/preload_utils.rb +1 -1
  17. data/lib/utils/wallaby/utils.rb +0 -6
  18. data/lib/wallaby/configuration/mapping.rb +0 -6
  19. data/lib/wallaby/constants.rb +10 -8
  20. data/lib/wallaby/core/version.rb +1 -1
  21. data/lib/wallaby/core.rb +4 -11
  22. metadata +35 -16
  23. data/lib/concerns/wallaby/rails_overridden_methods.rb +0 -42
  24. data/lib/concerns/wallaby/themeable.rb +0 -40
  25. data/lib/errors/wallaby/cell_handling.rb +0 -6
  26. data/lib/paginators/wallaby/resource_paginator.rb +0 -12
  27. data/lib/renderers/wallaby/cell.rb +0 -137
  28. data/lib/renderers/wallaby/cell_resolver.rb +0 -89
  29. data/lib/renderers/wallaby/custom_lookup_context.rb +0 -64
  30. data/lib/renderers/wallaby/custom_partial_renderer.rb +0 -33
  31. data/lib/renderers/wallaby/custom_renderer.rb +0 -16
  32. data/lib/utils/wallaby/cell_utils.rb +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8395907973df19277e9cb9a726b2c0ec37ea3ad7cbea4ea009447c9c71c17f4a
4
- data.tar.gz: c4a7d6d916973748ab861950818697a834a28c0ef1b614ce11ef6ba377a56847
3
+ metadata.gz: 52359ec55f58d6479a497e4d8bb412d2ff4e2a22781abb034721a580d6321a87
4
+ data.tar.gz: 14009b74724c111574addf3869e4f2bc5b96eae721a40a61c9885773bfb7eb05
5
5
  SHA512:
6
- metadata.gz: 77cbf958df5073c15ee4a20c00c2f9aaba1898136294e84b54ddeb82257c82d7c29f40084a5fa5c9f4788d65bb132a336033ff47dc2302f3ae7543f7ccaeb6e9
7
- data.tar.gz: 4b3ba5ff82410c0e63996be5358e2a9f33084f65ed45331531957431e3eb5ec36e8fb140e845ae4c6615d7ab67d5dc1efb0cc0ac34510e770819a08e8f8419a1
6
+ metadata.gz: 7e772e4457e4892ad725f6d0e65de0854f7cafeaa163c00fb3c4f3c9d88c44e25623bfe5b26fca01454e1bf2facf5d4f904c65a2bdf278ff3a22945679c0054b
7
+ data.tar.gz: a0a7fa9c558e05e8e62b4570265d4e2d1f063960550bf06148535be0cbb7aa571d416e932419cd0493b209e21c0ab249766de1299105eedbb62e5c3d416e902d
data/README.md CHANGED
@@ -1,31 +1,37 @@
1
- # Wallaby::Core
1
+ # [Wallaby::Core](https://github.com/wallaby-rails/wallaby-core)
2
2
 
3
- This gem contains the core interface that Wallaby is built upon.
3
+ [![Gem Version](https://badge.fury.io/rb/wallaby-core.svg)](https://badge.fury.io/rb/wallaby-core)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Travis CI](https://travis-ci.com/wallaby-rails/wallaby-core.svg?branch=master)](https://travis-ci.com/wallaby-rails/wallaby-core)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f16f8d87553424c1aacc/maintainability)](https://codeclimate.com/github/wallaby-rails/wallaby-core/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/f16f8d87553424c1aacc/test_coverage)](https://codeclimate.com/github/wallaby-rails/wallaby-core/test_coverage)
8
+ [![Inch CI](https://inch-ci.org/github/wallaby-rails/wallaby-core.svg?branch=master)](https://inch-ci.org/github/wallaby-rails/wallaby-core)
4
9
 
5
- ## Installation
10
+ Wallaby::Core contains all the core interfaces that [Wallaby](https://github.com/wallaby-rails/wallaby) gem is built upon.
6
11
 
7
- Add this line to your application's Gemfile:
12
+ ## Install
13
+
14
+ Add `Wallaby::Core` to `Gemfile`.
8
15
 
9
16
  ```ruby
10
17
  gem 'wallaby-core'
11
18
  ```
12
19
 
13
- And then execute:
20
+ And re-bundle.
14
21
 
15
22
  ```shell
16
- $ bundle
23
+ bundle install
17
24
  ```
18
25
 
19
- Or install it yourself as:
26
+ ## Documentation
20
27
 
21
- ```shell
22
- $ gem install wallaby-core
23
- ```
28
+ - [API Reference](https://www.rubydoc.info/gems/wallaby-core)
29
+ - [Change Logs](https://github.com/wallaby-rails/wallaby-core/blob/master/CHANGELOG.md)
24
30
 
25
- ## Contributing
31
+ ## Want to contribute?
26
32
 
27
- Bug reports and pull requests are welcome on GitHub at https://github.com/wallaby-rails/wallaby-core.
33
+ Raise an [issue](https://github.com/wallaby-rails/wallaby-core/issues/new), discuss and resolve!
28
34
 
29
35
  ## License
30
36
 
31
- This project is [MIT Licensed](LICENSE)
37
+ This project uses [MIT License](https://github.com/wallaby-rails/wallaby-core/blob/master/LICENSE).
@@ -31,31 +31,31 @@ module Wallaby
31
31
  # Not found page
32
32
  # @param exception [Exception] comes from **rescue_from**
33
33
  def not_found(exception = nil)
34
- error_rendering exception, __callee__
34
+ render_error exception, __callee__
35
35
  end
36
36
 
37
37
  # Bad request page
38
38
  # @param exception [Exception] comes from **rescue_from**
39
39
  def bad_request(exception = nil)
40
- error_rendering exception, __callee__
40
+ render_error exception, __callee__
41
41
  end
42
42
 
43
43
  # Unprocessable entity page
44
44
  # @param exception [Exception] comes from **rescue_from**
45
45
  def unprocessable_entity(exception = nil)
46
- error_rendering exception, __callee__
46
+ render_error exception, __callee__
47
47
  end
48
48
 
49
49
  # Internal server error page
50
50
  # @param exception [Exception] comes from **rescue_from**
51
51
  def internal_server_error(exception = nil)
52
- error_rendering exception, __callee__
52
+ render_error exception, __callee__
53
53
  end
54
54
 
55
55
  # Not implemented
56
56
  # @param exception [Exception] comes from **rescue_from**
57
57
  def not_implemented(exception = nil)
58
- error_rendering exception, __callee__
58
+ render_error exception, __callee__
59
59
  end
60
60
 
61
61
  # {https://api.rubyonrails.org/classes/ActionController/Helpers.html#method-i-helpers helpers}
@@ -72,7 +72,7 @@ module Wallaby
72
72
  # Capture exceptions and display the error using error template.
73
73
  # @param exception [Exception]
74
74
  # @param symbol [Symbol] http status symbol
75
- def error_rendering(exception, symbol)
75
+ def render_error(exception, symbol)
76
76
  Rails.logger.error exception
77
77
 
78
78
  @exception = exception
@@ -11,15 +11,16 @@ module Wallaby
11
11
  extend Paginatable::ClassMethods
12
12
  extend Resourcable::ClassMethods
13
13
  extend Servicable::ClassMethods
14
- extend Themeable::ClassMethods
14
+
15
+ include View
16
+ prepend Prefixable
17
+
15
18
  include Authorizable
16
19
  include Decoratable
17
20
  include Defaultable
18
21
  include Paginatable
19
- include RailsOverriddenMethods
20
22
  include Resourcable
21
23
  include Servicable
22
- include Themeable
23
24
 
24
25
  self.responder = ResourcesResponder
25
26
  respond_to :html
@@ -12,13 +12,13 @@ module Wallaby
12
12
  # Unauthorized page.
13
13
  # @param exception [Exception] exception comes from `rescue_from`
14
14
  def unauthorized(exception = nil)
15
- error_rendering exception, __callee__
15
+ render_error exception, __callee__
16
16
  end
17
17
 
18
18
  # Forbidden page.
19
19
  # @param exception [Exception] exception comes from `rescue_from`
20
20
  def forbidden(exception = nil)
21
- error_rendering exception, __callee__
21
+ render_error exception, __callee__
22
22
  end
23
23
 
24
24
  # @note This is a template method that can be overridden by subclasses
@@ -83,12 +83,6 @@ module Wallaby
83
83
  !authorized? action, subject
84
84
  end
85
85
 
86
- # @deprecated Use {#current_authorizer} instead. It will be removed from 5.3.*
87
- def authorizer
88
- Utils.deprecate 'deprecation.authorizer', caller: caller
89
- current_authorizer
90
- end
91
-
92
86
  protected
93
87
 
94
88
  # @param model_class [Class]
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wallaby
4
+ # Field helper for model decorator
5
+ module Prefixable
6
+ # @return [Array<String>] prefixes
7
+ def _prefixes
8
+ override_prefixes(
9
+ options: { mapping_actions: FORM_ACTIONS }
10
+ ) do |prefixes|
11
+ PrefixesBuilder.new(
12
+ prefixes: prefixes,
13
+ resources_name: current_resources_name,
14
+ script_name: request.env[SCRIPT_NAME]
15
+ ).execute
16
+
17
+ prefixes[0..prefixes.index(ResourcesController.controller_path)]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -58,11 +58,5 @@ module Wallaby
58
58
  klass.new current_model_class, current_authorizer, current_model_decorator
59
59
  end
60
60
  end
61
-
62
- # @deprecated Use {#current_servicer} instead. It will be removed from 5.3.*
63
- def current_model_service
64
- Utils.deprecate 'deprecation.current_model_service', caller: caller
65
- current_servicer
66
- end
67
61
  end
68
62
  end
@@ -12,15 +12,6 @@ module Wallaby
12
12
  # @see Wallaby::ModuleUtils.try_to
13
13
  delegate :try_to, to: ModuleUtils
14
14
 
15
- # Override the origin view_renderer to support {Wallaby::Cell} rendering
16
- # @!attribute [r] view_renderer
17
- # @see Wallaby::CustomRenderer
18
- def view_renderer
19
- return @view_renderer if @view_renderer.is_a? CustomRenderer
20
-
21
- @view_renderer = CustomRenderer.new @view_renderer.lookup_context
22
- end
23
-
24
15
  # Override origin method to handle URL for Wallaby engine.
25
16
  #
26
17
  # As Wallaby's routes are declared in a
@@ -3,12 +3,6 @@
3
3
  module Wallaby
4
4
  # Form helper
5
5
  module FormHelper
6
- # @deprecated Use {Wallaby::ResourcesHelper#type_render} instead. It will be removed from 5.3.*
7
- def form_type_partial_render(options = {}, locals = {}, &block)
8
- Utils.deprecate 'deprecation.form_type_partial_render', caller: caller
9
- type_render options, locals, &block
10
- end
11
-
12
6
  # To generate remote URL for auto select plugin.
13
7
  # @see https://github.com/reinteractive/wallaby/blob/master/app/assets/javascripts/wallaby/auto_select.js
14
8
  # auto_select.js
@@ -3,18 +3,6 @@
3
3
  module Wallaby
4
4
  # Helper methods for index action
5
5
  module IndexHelper
6
- # @deprecated This method is no longer in use. It will be removed from 5.3.*
7
- def index_params(parameters = params)
8
- Utils.deprecate 'deprecation.index_params', caller: caller
9
- parameters
10
- end
11
-
12
- # @deprecated Use {Wallaby::Paginatable#current_paginator} instead. It will be removed from 5.3.*
13
- def paginator_of(_model_class, _collection, _params)
14
- Utils.deprecate 'deprecation.paginator_of', caller: caller
15
- current_paginator
16
- end
17
-
18
6
  # Just a label
19
7
  # @return [String]
20
8
  def all_label
@@ -12,13 +12,6 @@ module Wallaby
12
12
  include Paginatable
13
13
  include Resourcable
14
14
  include Servicable
15
- include Themeable
16
-
17
- # @deprecated Use {#type_render} instead. It will be removed from 5.3.*
18
- def type_partial_render(options = {}, locals = {}, &block)
19
- Utils.deprecate 'deprecation.type_partial_render', caller: caller
20
- type_render options, locals, &block
21
- end
22
15
 
23
16
  # Render type cell/partial
24
17
  # @param partial_name [String]
@@ -1,34 +1,69 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wallaby
4
- # a parser to handle colon query
4
+ # A parser to parse colon query string and return a hash for transformer
5
+ # to consume
5
6
  class Parser < Parslet::Parser
7
+ # @!method parse(str)
8
+ # Parse string into Abstract Syntax Tree for transformer to consume
9
+ # @param str [String]
10
+ # @return [Hash] Abstract Syntax Tree
11
+
12
+ # Case insensitive string match
13
+ # @param str [String]
14
+ def stri(str)
15
+ str.chars.map! { |c| match["#{c.upcase}#{c.downcase}"] }.reduce :>>
16
+ end
17
+
6
18
  root(:statement)
7
- rule(:statement) { expression >> (space >> expression).repeat }
8
- rule(:expression) { colon_query | general_keyword }
19
+ rule(:statement) { expression >> (spaces >> expression).repeat }
20
+ rule(:expression) { colon_query | quoted_string | string | any.repeat(0).as(:null) }
9
21
  rule(:colon_query) do
10
- name.as(:left) >> operator.as(:op) >> keywords.as(:right)
22
+ name.as(:left) >> operator.as(:op) >> values.as(:right)
23
+ end
24
+
25
+ # colon query
26
+ begin
27
+ # name starts with letter
28
+ rule(:name) { letter >> ((colon | spaces).absent? >> any).repeat }
29
+
30
+ # operator starts with colon
31
+ rule(:operator) do
32
+ colon >> (
33
+ (colon | spaces | quote | comma | digit | letter).absent? >> any
34
+ ).repeat(0, 3)
35
+ end
36
+
37
+ # values separated by comma
38
+ rule(:values) { value >> (comma >> value).repeat }
39
+ rule(:value) { quoted_string | data }
40
+ rule(:data) do
41
+ null.as(:null) | boolean.as(:boolean) |
42
+ (spaces.absent? >> comma.absent? >> any).repeat.as(:string)
43
+ end
11
44
  end
12
- rule(:name) { (space.absent? >> colon.absent? >> any).repeat(1) }
13
- rule(:operator) { colon >> match('[^\s\'\"\:\,0-9a-zA-Z]').repeat(0, 3) }
14
- rule(:keywords) { general_keyword >> (comma >> general_keyword).repeat }
15
- rule(:general_keyword) { quoted_keyword | keyword }
16
45
 
17
46
  # basic elements
18
- rule(:quoted_keyword) do
47
+ rule(:quoted_string) do
19
48
  open_quote >>
20
- (close_quote.absent? >> any).repeat.as(:keyword) >>
49
+ (close_quote.absent? >> any).repeat.as(:string) >>
21
50
  close_quote
22
51
  end
23
- rule(:keyword) { ((space | comma).absent? >> any).repeat.as(:keyword) }
52
+ rule(:string) { (spaces.absent? >> any).repeat(1).as(:string) }
24
53
 
25
54
  # atomic entities
55
+ rule(:null) { stri('nil') | stri('null') }
56
+ rule(:boolean) { stri('true') | stri('false') }
57
+ rule(:letter) { match['a-zA-Z'] }
58
+ rule(:digit) { match['0-9'] }
59
+ rule(:dot) { str('.') }
26
60
  rule(:comma) { str(',') }
27
- rule(:space) { match('\s').repeat(1) }
61
+ rule(:spaces) { match['\s'].repeat(1) }
28
62
  rule(:colon) { str(':') }
63
+ rule(:quote) { match['\'\"'] }
29
64
 
30
65
  # open-close elements
31
- rule(:open_quote) { match('[\'\"]').capture(:quote) }
32
- rule(:close_quote) { dynamic { |_src, ctx| str(ctx.captures[:quote]) } }
66
+ rule(:open_quote) { quote.capture(:quoting) }
67
+ rule(:close_quote) { dynamic { |_src, ctx| str(ctx.captures[:quoting]) } }
33
68
  end
34
69
  end
@@ -3,64 +3,30 @@
3
3
  module Wallaby
4
4
  # To extend prefixes to provide more possibility
5
5
  class PrefixesBuilder
6
- # @param origin_prefixes [Array<string>] a list of all the origin prefixes
7
- # @param action_name [String] action name
8
- # @param resources_name [String] resources name
9
- # @param script_name [String] script name
10
- # @param theme_name [String] theme name
11
- def self.build(origin_prefixes:, action_name:, resources_name:, script_name:, theme_name:)
12
- new(
13
- origin_prefixes: origin_prefixes,
14
- action_name: action_name,
15
- resources_name: resources_name,
16
- script_name: script_name,
17
- theme_name: theme_name
18
- ).send :build
19
- end
6
+ include ActiveModel::Model
20
7
 
21
- private
8
+ attr_accessor :prefixes
9
+ attr_accessor :resources_name
10
+ attr_accessor :script_name
22
11
 
23
- # Constructor
24
- def initialize(origin_prefixes:, action_name:, resources_name:, script_name:, theme_name:)
25
- @origin_prefixes = origin_prefixes
26
- @action_name = action_name
27
- @resources_name = resources_name
28
- @script_name = script_name
29
- @theme_name = theme_name
30
- end
12
+ def execute
13
+ return if prefixes.include? resources_path
31
14
 
32
- # @return [Array<String>] prefixes
33
- def build
34
- prefixes = minimal_prefixes
35
- prefixes.unshift mounted_prefix unless prefixes.include? resources_path
36
- prefixes.uniq.compact.each_with_object([]) do |prefix, result|
37
- result << "#{prefix}/#{suffix}" << prefix
38
- end
39
- end
15
+ full_prefix = [script_path, resources_path].compact.join(SLASH)
40
16
 
41
- # @return [Array<String>] prefixes starting from wallaby controller path
42
- def minimal_prefixes
43
- index = @origin_prefixes.index ResourcesController.controller_path
44
- @origin_prefixes.slice(0..index).tap do |prefixes|
45
- insert_index = prefixes.length > 1 ? -2 : 0
46
- prefixes.insert insert_index, @theme_name if @theme_name.present?
47
- end
48
- end
17
+ return if prefixes.include? full_prefix
49
18
 
50
- # @return [String] a prefix of the mouted path
51
- def mounted_prefix
52
- prefix = (@script_name || '').sub(%r{^/}, '')
53
- prefix << SLASH if prefix.present?
54
- prefix << resources_path if resources_path
19
+ prefixes.insert 0, full_prefix
55
20
  end
56
21
 
57
- # @return [String]
58
- def suffix
59
- @suffix ||= CellUtils.to_action_prefix @action_name
60
- end
22
+ private
61
23
 
62
24
  def resources_path
63
- @resources_path ||= @resources_name.try :gsub, COLONS, SLASH
25
+ @resources_path ||= resources_name.try :gsub, COLONS, SLASH
26
+ end
27
+
28
+ def script_path
29
+ @script_path ||= script_name.try :[], 1..-1
64
30
  end
65
31
  end
66
32
  end
@@ -31,7 +31,7 @@ module Wallaby
31
31
  # @param locals [Hash]
32
32
  # @param action [String]
33
33
  def complete(locals, action)
34
- action_name = CellUtils.to_action_prefix action
34
+ action_name = FORM_ACTIONS[action] || action
35
35
  locals[:metadata] = locals[:object].public_send :"#{action_name}_metadata_of", locals[:field_name]
36
36
  locals[:value] = locals[:object].public_send locals[:field_name]
37
37
  end
@@ -22,7 +22,7 @@ module Wallaby
22
22
  # at highest precedence
23
23
  def eager_load_paths
24
24
  Rails.configuration.eager_load_paths.sort_by do |path|
25
- - path.index(%r{/models$}).to_i
25
+ - path.to_s.index(%r{/models$}).to_i
26
26
  end
27
27
  end
28
28
 
@@ -11,12 +11,6 @@ module Wallaby
11
11
  warn I18n.t(key, options.merge(from: caller[0]))
12
12
  end
13
13
 
14
- # @deprecated Use {Wallaby::FilterUtils.filter_name_by} instead. It will be removed from 5.3.*
15
- def self.find_filter_name(filter_name, filters)
16
- deprecate 'deprecation.find_filter_name', caller: caller
17
- FilterUtils.filter_name_by filter_name, filters
18
- end
19
-
20
14
  # @see http://stackoverflow.com/a/8710663/1326499
21
15
  # @param object [Object]
22
16
  # @return [Object] a clone object
@@ -80,12 +80,6 @@ module Wallaby
80
80
  @model_servicer ||= ModelServicer
81
81
  end
82
82
 
83
- # @deprecated Use {#model_paginator=} instead. It will be removed from 5.3.*
84
- def resource_paginator=(resource_paginator)
85
- Utils.deprecate 'deprecation.resource_paginator=', caller: caller
86
- self.model_paginator = resource_paginator
87
- end
88
-
89
83
  # @!attribute [w] model_authorizer
90
84
  attr_writer :model_authorizer
91
85
 
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wallaby
4
- EMPTY_STRING = ''.html_safe
5
- EMPTY_HASH = {}.freeze
6
- EMPTY_ARRAY = [].freeze
7
- SPACE = ' '
8
- SLASH = '/'
9
- COLONS = '::'
10
- COMMA = ','
11
- DOT = '.'
4
+ EMPTY_STRING = ''.html_safe.freeze # :nodoc:
5
+ EMPTY_HASH = {}.freeze # :nodoc:
6
+ EMPTY_ARRAY = [].freeze # :nodoc:
7
+ SPACE = ' ' # :nodoc:
8
+ SLASH = '/' # :nodoc:
9
+ COLONS = '::' # :nodoc:
10
+ COMMA = ',' # :nodoc:
11
+ DOT = '.' # :nodoc:
12
+ UNDERSCORE = '_' # :nodoc:
13
+ PCT = '%' # :nodoc:
12
14
 
13
15
  # Default page size for {Wallaby::Configuration::Pagination#page_size}
14
16
  DEFAULT_PAGE_SIZE = 20
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Wallaby
4
4
  module Core
5
- VERSION = '0.1.2'
5
+ VERSION = '0.2.0' # :nodoc:
6
6
  end
7
7
  end
data/lib/wallaby/core.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_model'
3
4
  require 'parslet'
4
5
  require 'responders'
6
+ require 'wallaby/view'
5
7
 
6
8
  require 'wallaby/core/version'
7
9
  require 'wallaby/constants'
@@ -23,7 +25,6 @@ require 'routes/wallaby/resources_router'
23
25
  require 'tree/wallaby/node'
24
26
  require 'parsers/wallaby/parser'
25
27
 
26
- require 'utils/wallaby/cell_utils'
27
28
  require 'utils/wallaby/field_utils'
28
29
  require 'utils/wallaby/filter_utils'
29
30
  require 'utils/wallaby/model_utils'
@@ -40,11 +41,11 @@ require 'concerns/wallaby/defaultable'
40
41
  require 'concerns/wallaby/engineable'
41
42
  require 'concerns/wallaby/fieldable'
42
43
  require 'concerns/wallaby/paginatable'
43
- require 'concerns/wallaby/rails_overridden_methods'
44
+ require 'concerns/wallaby/prefixable'
44
45
  require 'concerns/wallaby/resourcable'
45
46
  require 'concerns/wallaby/servicable'
46
47
  require 'concerns/wallaby/shared_helpers'
47
- require 'concerns/wallaby/themeable'
48
+ # require 'concerns/wallaby/themeable'
48
49
 
49
50
  require 'interfaces/wallaby/mode'
50
51
  require 'interfaces/wallaby/model_decorator'
@@ -59,7 +60,6 @@ require 'errors/wallaby/not_implemented'
59
60
  require 'errors/wallaby/not_found'
60
61
  require 'errors/wallaby/model_not_found'
61
62
  require 'errors/wallaby/resource_not_found'
62
- require 'errors/wallaby/cell_handling'
63
63
 
64
64
  require 'errors/wallaby/forbidden'
65
65
  require 'errors/wallaby/not_authenticated'
@@ -68,7 +68,6 @@ require 'errors/wallaby/unprocessable_entity'
68
68
  require 'decorators/wallaby/resource_decorator'
69
69
  require 'servicers/wallaby/model_servicer'
70
70
  require 'paginators/wallaby/model_paginator'
71
- require 'paginators/wallaby/resource_paginator'
72
71
  require 'authorizers/wallaby/model_authorizer'
73
72
  require 'authorizers/wallaby/default_authorization_provider'
74
73
  require 'authorizers/wallaby/cancancan_authorization_provider'
@@ -103,12 +102,6 @@ require 'helpers/wallaby/application_helper'
103
102
  require 'responders/wallaby/resources_responder'
104
103
  require 'responders/wallaby/json_api_responder'
105
104
 
106
- require 'renderers/wallaby/cell'
107
- require 'renderers/wallaby/cell_resolver'
108
- require 'renderers/wallaby/custom_lookup_context'
109
- require 'renderers/wallaby/custom_renderer'
110
- require 'renderers/wallaby/custom_partial_renderer'
111
-
112
105
  require 'adaptors/wallaby/custom'
113
106
  require 'adaptors/wallaby/custom/default_provider'
114
107
  require 'adaptors/wallaby/custom/model_finder'
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wallaby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tian Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2020-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: parslet
14
+ name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 4.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: parslet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: responders
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: wallaby-view
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.2
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec-rails
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -113,13 +141,11 @@ files:
113
141
  - lib/concerns/wallaby/engineable.rb
114
142
  - lib/concerns/wallaby/fieldable.rb
115
143
  - lib/concerns/wallaby/paginatable.rb
116
- - lib/concerns/wallaby/rails_overridden_methods.rb
144
+ - lib/concerns/wallaby/prefixable.rb
117
145
  - lib/concerns/wallaby/resourcable.rb
118
146
  - lib/concerns/wallaby/servicable.rb
119
147
  - lib/concerns/wallaby/shared_helpers.rb
120
- - lib/concerns/wallaby/themeable.rb
121
148
  - lib/decorators/wallaby/resource_decorator.rb
122
- - lib/errors/wallaby/cell_handling.rb
123
149
  - lib/errors/wallaby/forbidden.rb
124
150
  - lib/errors/wallaby/general_error.rb
125
151
  - lib/errors/wallaby/invalid_error.rb
@@ -146,13 +172,7 @@ files:
146
172
  - lib/interfaces/wallaby/model_pagination_provider.rb
147
173
  - lib/interfaces/wallaby/model_service_provider.rb
148
174
  - lib/paginators/wallaby/model_paginator.rb
149
- - lib/paginators/wallaby/resource_paginator.rb
150
175
  - lib/parsers/wallaby/parser.rb
151
- - lib/renderers/wallaby/cell.rb
152
- - lib/renderers/wallaby/cell_resolver.rb
153
- - lib/renderers/wallaby/custom_lookup_context.rb
154
- - lib/renderers/wallaby/custom_partial_renderer.rb
155
- - lib/renderers/wallaby/custom_renderer.rb
156
176
  - lib/responders/wallaby/json_api_responder.rb
157
177
  - lib/responders/wallaby/resources_responder.rb
158
178
  - lib/routes/wallaby/resources_router.rb
@@ -171,7 +191,6 @@ files:
171
191
  - lib/services/wallaby/type_renderer.rb
172
192
  - lib/support/action_dispatch/routing/mapper.rb
173
193
  - lib/tree/wallaby/node.rb
174
- - lib/utils/wallaby/cell_utils.rb
175
194
  - lib/utils/wallaby/field_utils.rb
176
195
  - lib/utils/wallaby/filter_utils.rb
177
196
  - lib/utils/wallaby/model_utils.rb
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # This is a collection of the helper methods that overrides the rails methods
5
- module RailsOverriddenMethods
6
- protected
7
-
8
- # Override {https://github.com/rails/rails/blob/master/actionview/lib/action_view/view_paths.rb
9
- # ActionView::ViewPaths::ClassMethods#_prefixes} to extend the prefixes for **ActionView::ViewPaths** to look up
10
- # in below precedence from high to low:
11
- #
12
- # - :mounted_path/:resources_name/:action_prefix (e.g. `admin/products/index`)
13
- # - :mounted_path/:resources_name (e.g. `admin/products`)
14
- # - :controller_path/:action_prefix
15
- # - :controller_path
16
- # - :parent_controller_path/:action_prefix
17
- # - :parent_controller_path
18
- # - :more_parent_controller_path/:action_prefix
19
- # - :more_parent_controller_path
20
- # - :theme_name/:action_prefix
21
- # - :theme_name
22
- # - wallaby/resources/:action_prefix
23
- # - wallaby/resources
24
- # @return [Array<String>]
25
- def _prefixes
26
- @_prefixes ||= PrefixesBuilder.build(
27
- origin_prefixes: super,
28
- theme_name: current_theme_name,
29
- resources_name: current_resources_name,
30
- script_name: request.env[SCRIPT_NAME],
31
- action_name: params[:action]
32
- )
33
- end
34
-
35
- # Override to provide support for cell lookup
36
- # @return [Wallaby::CustomLookupContext]
37
- def lookup_context
38
- @_lookup_context ||= # rubocop:disable Naming/MemoizedInstanceVariableName
39
- CustomLookupContext.normalize(super, prefixes: _prefixes)
40
- end
41
- end
42
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # Theme related methods
5
- module Themeable
6
- # Configurable attributes
7
- module ClassMethods
8
- # @!attribute [w] theme_name
9
- def theme_name=(theme_name)
10
- layout theme_name
11
- @theme_name = theme_name
12
- end
13
-
14
- # @!attribute [r] theme_name
15
- # The theme name is used to apply a set of frontend (html/css/javascript) implementation.
16
- #
17
- # When theme name is set to e.g. `custom_theme`, the following changes will be made:
18
- #
19
- # - layout will be set to the same name `custom_theme`
20
- # - it will be added to the partial lookup prefixes right on top of `wallaby/resources` prefix.
21
- #
22
- # Once theme name is set, all its controller subclasses will inherit the same theme name
23
- # @example To set an theme name:
24
- # class Admin::ApplicationController < Wallaby::ResourcesController
25
- # self.theme_name = 'admin_theme'
26
- # end
27
- # @return [String, Symbol, nil] theme name
28
- # @since 5.2.0
29
- def theme_name
30
- @theme_name ||= ModuleUtils.try_to superclass, :theme_name
31
- end
32
- end
33
-
34
- # @return [String, Symbol, nil] theme name
35
- # @since 5.2.0
36
- def current_theme_name
37
- controller_to_get __callee__, :theme_name
38
- end
39
- end
40
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- class CellHandling < ::StandardError
5
- end
6
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # Resource paginator
5
- class ResourcePaginator < ModelPaginator
6
- base_class!
7
-
8
- def self.inherited(_sub_class)
9
- Utils.deprecate 'deprecation.resource_paginator_inheirtance', caller: caller
10
- end
11
- end
12
- end
@@ -1,137 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # In order to improve the rendering performance, cell is designed as simple partial component.
5
- # @since 5.2.0
6
- class Cell
7
- # @!attribute [r] context
8
- # @return [Object] view context
9
- attr_reader :context
10
-
11
- # @!attribute [r] local_assigns
12
- # @return [Hash] a list of local_assigns containing {#object}, {#field_name}, {#value}, {#metadata} and {#form}
13
- attr_reader :local_assigns
14
-
15
- # @!attribute [r] buffer
16
- # @return [String] output string buffer
17
- attr_reader :buffer
18
-
19
- delegate(*ERB::Util.singleton_methods, to: ERB::Util)
20
-
21
- # @param context [ActionView::Context] view context
22
- # @param local_assigns [Hash] local variables
23
- def initialize(context, local_assigns)
24
- @context = context
25
- @local_assigns = local_assigns
26
- end
27
-
28
- # @!attribute [r] object
29
- # @return [Object] object
30
- def object
31
- local_assigns[:object]
32
- end
33
-
34
- # @!attribute [w] object
35
- def object=(object)
36
- local_assigns[:object] = object
37
- end
38
-
39
- # @!attribute [r] field_name
40
- # @return [String] field name
41
- def field_name
42
- local_assigns[:field_name]
43
- end
44
-
45
- # @!attribute [w] field_name
46
- def field_name=(field_name)
47
- local_assigns[:field_name] = field_name
48
- end
49
-
50
- # @!attribute [r] value
51
- # @return [String] value
52
- def value
53
- local_assigns[:value]
54
- end
55
-
56
- # @!attribute [w] value
57
- def value=(value)
58
- local_assigns[:value] = value
59
- end
60
-
61
- # @!attribute [r] metadata
62
- # @return [String] metadata
63
- def metadata
64
- local_assigns[:metadata]
65
- end
66
-
67
- # @!attribute [w] metadata
68
- def metadata=(metadata)
69
- local_assigns[:metadata] = metadata
70
- end
71
-
72
- # @!attribute [r] form
73
- # @return [ActionView::Helpers::FormBuilder] form object
74
- def form
75
- local_assigns[:form]
76
- end
77
-
78
- # @!attribute [w] form
79
- def form=(form)
80
- local_assigns[:form] = form
81
- end
82
-
83
- # @note this is a template method that can be overridden by subclasses
84
- # Produce output for this cell component.
85
- #
86
- # Please note that the output doesn't include the buffer produced by {#concat}.
87
- # Therefore, use {#render_complete} method instead when the cell is rendered.
88
- def render; end
89
-
90
- # This method produces the complete rendered string including the buffer produced by {#concat}.
91
- # @return [String] output of the cell
92
- def render_complete(&block)
93
- @buffer = EMPTY_STRING.dup # reset buffer before rendering
94
- last_part = render(&block)
95
- @buffer << last_part.to_s
96
- end
97
-
98
- # Append string to output buffer
99
- # @param string [String] string to concat
100
- def concat(string)
101
- (@buffer ||= EMPTY_STRING.dup) << string
102
- end
103
-
104
- # @overload at(name)
105
- # Get view instance variable value
106
- # @example To get view instance variable value
107
- # at('name') # => get value of `@name` from the view
108
- # @param name [String, Symbol] view instance variable name without `@`
109
- # @overload at(name, value)
110
- # Set view instance variable value
111
- # @example To set view instance variable value
112
- # at('name', value) # => set value of `@name` in the view
113
- # @param name [String, Symbol] view instance variable name without `@`
114
- # @param value [object] value
115
- # @return [object] view instance variable value
116
- def at(*args)
117
- raise ArgumentError unless args.length.in? [1, 2]
118
- return context.instance_variable_get :"@#{args.first}" if args.length == 1
119
-
120
- context.instance_variable_set :"@#{args.first}", args.last
121
- end
122
-
123
- private
124
-
125
- # Delegate missing method to {#context}
126
- def method_missing(method_id, *args, &block)
127
- return super unless context.respond_to? method_id
128
-
129
- context.public_send method_id, *args, &block
130
- end
131
-
132
- # Delegate missing method check to {#context}
133
- def respond_to_missing?(method_id, _include_private)
134
- context.respond_to?(method_id) || super
135
- end
136
- end
137
- end
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # Resolver to provide support for cell and partial
5
- # @since 5.2.0
6
- class CellResolver < ActionView::OptimizedFileSystemResolver
7
- # for Rails 5.2 and below
8
- begin
9
- # @note this method is only applicable to Rails 5.2 and below
10
- # A cell query looks like:
11
- #
12
- # ```
13
- # app/views/wallaby/resources/index/integer{_en,}{_html,}.rb
14
- # ```
15
- #
16
- # Wallaby adds it to the front of the whole query as below:
17
- #
18
- # ```
19
- # {app/views/wallaby/resources/index/integer{_en,}{_html,}.rb,
20
- # app/views/wallaby/resources/index/_integer{.en,}{.html,}{.erb,}}
21
- # ```
22
- # @param path [String]
23
- # @param details [Hash]
24
- # see {https://api.rubyonrails.org/classes/ActionView/LookupContext/ViewPaths.html#method-i-detail_args_for
25
- # Detials from ViewPaths}
26
- # @return [String] a path query
27
- def build_query(path, details)
28
- # NOTE: super is impacted by {#escape_entry}
29
- origin = super
30
- file_name = origin[%r{(?<=/\{,_\})[^/\{]+}]
31
- return origin unless file_name
32
-
33
- base_dir = origin.gsub(%r{/[^/]*$}, '')
34
- locales = convert details[:locale]
35
- formats = convert details[:formats]
36
- cell = "#{base_dir}/#{file_name}{#{locales}}{#{formats}}.rb"
37
- "{#{cell},#{origin}}"
38
- end
39
- end
40
-
41
- # for Rails 6 and above
42
- begin
43
- # @note this method is only applicable to Rails 6 and above
44
- # This is to extend the origin functionality to enable to return cell file.
45
- # at highest precedence.
46
- # @param path [String]
47
- # @param details [Hash]
48
- # @return [ActionView::Template] found template
49
- def find_template_paths_from_details(path, details)
50
- details[:handlers].unshift(:rb) if details[:handlers].try(:first) != :rb
51
- super
52
- end
53
-
54
- # @note this method is only applicable to Rails 6 and above
55
- # This is to extend the origin functionality to enable to query cell files.
56
- # @param path [String]
57
- # @param details [Hash]
58
- # @return [Regexp]
59
- def build_regex(path, details)
60
- origin = super.source
61
- Regexp.new(
62
- origin
63
- .gsub(%r{/\{,_\}([^/]+)\z}, '/_?\\1')
64
- .gsub('\\.', '[_\\.]')
65
- .gsub('raw|', 'rb|raw|')
66
- )
67
- end
68
- end
69
-
70
- # This is to extend the origin funcationality to enable the query
71
- # to look for cell files
72
- # @example extend the query
73
- # escape_entry('integer') # => '/{,_}integer'
74
- # @param entry [String]
75
- # @return [String] an escaped and extended query
76
- def escape_entry(entry)
77
- super.gsub(%r{/_([^/]+)\z}, '/{,_}\1')
78
- end
79
-
80
- private
81
-
82
- # @example concat a list of values into a string
83
- # convert(['html', 'csv']) # => '_html,_cvs,'
84
- # @param values [Array<String>]
85
- def convert(values)
86
- (values.map { |v| "_#{v}" } << '').join ','
87
- end
88
- end
89
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # A custom lookup context that uses {Wallaby::CellResolver} to find cell/partial
5
- class CustomLookupContext < ::ActionView::LookupContext
6
- def self.normalize(lookup, details: nil, prefixes: nil)
7
- return lookup if lookup.is_a? self
8
-
9
- CustomLookupContext.new(
10
- lookup.view_paths,
11
- details || lookup.instance_variable_get('@details'),
12
- prefixes || lookup.prefixes
13
- )
14
- end
15
-
16
- # @note for Rails 6 and above
17
- # It overrides the origin method to convert paths to {Wallaby::CellResolver}
18
- # @param paths [Array]
19
- # @return [ActionView::PathSet]
20
- def build_view_paths(paths)
21
- ActionView::PathSet.new Array(paths).map(&method(:convert))
22
- end
23
-
24
- # @note for Rails 5.2 and below
25
- # It overrides the origin method to convert paths to {Wallaby::CellResolver}
26
- # @param paths [Array]
27
- # @return [ActionView::PathSet]
28
- def view_paths=(paths)
29
- @view_paths = build_view_paths paths
30
- end
31
-
32
- # It overrides the oirgin method to call the origin `find_template` and cache the result during a request.
33
- # @param name [String]
34
- # @param prefixes [Array<String>]
35
- # @param partial [Boolean]
36
- # @param keys [Array<String>] keys of local variables
37
- # @param options [Hash]
38
- def find_template(name, prefixes = [], partial = false, keys = [], options = {})
39
- prefixes = [] if partial && name.include?(SLASH) # reset the prefixes if `/` is detected
40
- key = [name, prefixes, partial, keys, options].map(&:inspect).join(SLASH)
41
- cached_lookup[key] ||= super
42
- end
43
-
44
- protected
45
-
46
- # @!attribute [r] cached_lookup
47
- # Cached lookup result
48
- def cached_lookup
49
- @cached_lookup ||= {}
50
- end
51
-
52
- # Convert path to {Wallaby::CellResolver}
53
- # @param path [Object]
54
- # @return [Wallaby::CellResolver]
55
- def convert(path)
56
- case path
57
- when ActionView::OptimizedFileSystemResolver, Pathname, String
58
- CellResolver.new path.to_s
59
- else
60
- path
61
- end
62
- end
63
- end
64
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # Custom partial renderer to provide support for cell rendering
5
- class CustomPartialRenderer < ::ActionView::PartialRenderer
6
- # When a type partial is found, it works as usual.
7
- #
8
- # But when a cell is found, there is an exception {Wallaby::CellHandling} raised. This error will be captured,
9
- # and the cell will be rendered.
10
- # @param context [ActionView::Context]
11
- # @param options [Hash]
12
- # @param block [Proc]
13
- # @return [String] HTML output
14
- def render(context, options, block)
15
- super.try do |rendered|
16
- ModuleUtils.try_to(rendered, :body) || # Rails 6 and above
17
- rendered # Rails 5.2 and below
18
- end
19
- rescue CellHandling => e
20
- CellUtils.render context, e.message, options[:locals], &block
21
- end
22
-
23
- # Override origin method to stop rendering when a cell is found.
24
- # @return [ActionView::Template] partial template
25
- # @raise [Wallaby:::CellHandling] when a cell is found
26
- def find_partial(*)
27
- super.tap do |partial|
28
- cell = CellUtils.find_cell(partial.identifier, partial.inspect)
29
- raise CellHandling, cell if cell
30
- end
31
- end
32
- end
33
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # Custom view renderer to provide support for cell rendering
5
- class CustomRenderer < ::ActionView::Renderer
6
- def initialize(lookup_context)
7
- super CustomLookupContext.normalize(lookup_context)
8
- end
9
-
10
- # @return [String] HTML output
11
- # @see Wallaby::CustomPartialRenderer
12
- def render_partial(context, options, &block) #:nodoc:
13
- CustomPartialRenderer.new(lookup_context).render(context, options, block)
14
- end
15
- end
16
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Wallaby
4
- # Cell utils
5
- module CellUtils
6
- class << self
7
- # Render a cell and produce output
8
- # @param context [ActionView::Context]
9
- # @param file_name [String]
10
- # @param locals [Hash]
11
- # @return [String] output
12
- def render(context, file_name, locals = {}, &block)
13
- snake_class = file_name[%r{(?<=app/views/).+(?=\.rb)}]
14
- cell_class = snake_class.camelize.constantize
15
- Rails.logger.info " Rendered [cell] #{file_name}"
16
- cell_class.new(context, locals).render_complete(&block)
17
- end
18
-
19
- # Check if a partial is a cell or not
20
- # @param partial_path [String]
21
- # @return [true] if partial is a `rb` file
22
- # @return [false] otherwise
23
- def find_cell(*partials)
24
- partials.find { |partial| partial.end_with? '.rb' }
25
- end
26
-
27
- # @param action_name [String, Symbol]
28
- # @return [String, Symbol] action prefix
29
- def to_action_prefix(action_name)
30
- FORM_ACTIONS[action_name] || action_name
31
- end
32
- end
33
- end
34
- end