pakyow-presenter 1.0.0.rc5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -108
  3. data/lib/pakyow/application/actions/presenter/auto_render.rb +17 -0
  4. data/lib/pakyow/application/behavior/presenter/error_rendering.rb +127 -0
  5. data/lib/pakyow/application/behavior/presenter/exposures.rb +31 -0
  6. data/lib/pakyow/application/behavior/presenter/implicit_rendering.rb +23 -0
  7. data/lib/pakyow/application/behavior/presenter/initializing.rb +69 -0
  8. data/lib/pakyow/application/behavior/presenter/modes.rb +120 -0
  9. data/lib/pakyow/application/behavior/presenter/versions.rb +73 -0
  10. data/lib/pakyow/application/behavior/presenter/watching.rb +23 -0
  11. data/lib/pakyow/{presenter/behavior/config.rb → application/config/presenter.rb} +3 -3
  12. data/lib/pakyow/application/helpers/presenter/rendering.rb +20 -0
  13. data/lib/pakyow/plugin/helpers/presenter/rendering.rb +34 -0
  14. data/lib/pakyow/presenter/errors.rb +1 -3
  15. data/lib/pakyow/presenter/framework.rb +18 -18
  16. data/lib/pakyow/presenter.rb +1 -1
  17. metadata +23 -24
  18. data/lib/pakyow/actions/presenter/auto_render.rb +0 -15
  19. data/lib/pakyow/plugin/helpers/rendering.rb +0 -32
  20. data/lib/pakyow/presenter/behavior/error_rendering.rb +0 -125
  21. data/lib/pakyow/presenter/behavior/exposures.rb +0 -29
  22. data/lib/pakyow/presenter/behavior/implicit_rendering.rb +0 -21
  23. data/lib/pakyow/presenter/behavior/initializing.rb +0 -67
  24. data/lib/pakyow/presenter/behavior/modes.rb +0 -118
  25. data/lib/pakyow/presenter/behavior/versions.rb +0 -71
  26. data/lib/pakyow/presenter/behavior/watching.rb +0 -21
  27. data/lib/pakyow/presenter/helpers/rendering.rb +0 -18
@@ -48,13 +48,11 @@ module Pakyow
48
48
  <<~MESSAGE
49
49
  #{super}
50
50
 
51
- If you want to call backend code instead, create a controller endpoint that handles this request:
51
+ If you want to call backend code instead, create a controller route that handles this request:
52
52
 
53
53
  get "#{@context}" do
54
54
  # your code here
55
55
  end
56
-
57
- * [Learn about controllers &rarr;](https://pakyow.com/docs/routing/)
58
56
  MESSAGE
59
57
  end
60
58
  end
@@ -5,16 +5,16 @@ require "pakyow/framework"
5
5
  require "pakyow/support/indifferentize"
6
6
  require "pakyow/support/core_refinements/string/normalization"
7
7
 
8
- require "pakyow/presenter/behavior/config"
9
- require "pakyow/presenter/behavior/error_rendering"
10
- require "pakyow/presenter/behavior/exposures"
11
- require "pakyow/presenter/behavior/implicit_rendering"
12
- require "pakyow/presenter/behavior/initializing"
13
- require "pakyow/presenter/behavior/modes"
14
- require "pakyow/presenter/behavior/versions"
15
- require "pakyow/presenter/behavior/watching"
8
+ require "pakyow/application/config/presenter"
9
+ require "pakyow/application/behavior/presenter/error_rendering"
10
+ require "pakyow/application/behavior/presenter/exposures"
11
+ require "pakyow/application/behavior/presenter/implicit_rendering"
12
+ require "pakyow/application/behavior/presenter/initializing"
13
+ require "pakyow/application/behavior/presenter/modes"
14
+ require "pakyow/application/behavior/presenter/versions"
15
+ require "pakyow/application/behavior/presenter/watching"
16
16
 
17
- require "pakyow/presenter/helpers/rendering"
17
+ require "pakyow/application/helpers/presenter/rendering"
18
18
 
19
19
  require "pakyow/presenter/renderable"
20
20
 
@@ -83,14 +83,14 @@ module Pakyow
83
83
  aspect :components
84
84
  aspect :presenters
85
85
 
86
- register_helper :active, Helpers::Rendering
86
+ register_helper :active, Application::Helpers::Presenter::Rendering
87
87
 
88
88
  isolated :Connection do
89
89
  include Renderable
90
90
  end
91
91
 
92
92
  isolated :Controller do
93
- include Behavior::ImplicitRendering
93
+ include Application::Behavior::Presenter::ImplicitRendering
94
94
 
95
95
  action :verify_form_metadata do
96
96
  if metadata = params[:"pw-form"]
@@ -146,13 +146,13 @@ module Pakyow
146
146
  config.version = app_version.to_s
147
147
  end
148
148
 
149
- include Behavior::Config
150
- include Behavior::ErrorRendering
151
- include Behavior::Exposures
152
- include Behavior::Initializing
153
- include Behavior::Modes
154
- include Behavior::Versions
155
- include Behavior::Watching
149
+ include Application::Config::Presenter
150
+ include Application::Behavior::Presenter::ErrorRendering
151
+ include Application::Behavior::Presenter::Exposures
152
+ include Application::Behavior::Presenter::Initializing
153
+ include Application::Behavior::Presenter::Modes
154
+ include Application::Behavior::Presenter::Versions
155
+ include Application::Behavior::Presenter::Watching
156
156
 
157
157
  def view_info_for_path(path)
158
158
  path = String.collapse_path(path)
@@ -30,4 +30,4 @@ require "pakyow/presenter/presenters/form"
30
30
 
31
31
  require "pakyow/presenter/errors"
32
32
 
33
- require "pakyow/actions/presenter/auto_render"
33
+ require "pakyow/application/actions/presenter/auto_render"
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
- - Bret Young
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2019-07-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: pakyow-core
@@ -17,42 +16,42 @@ dependencies:
17
16
  requirements:
18
17
  - - '='
19
18
  - !ruby/object:Gem::Version
20
- version: 1.0.0.rc5
19
+ version: 1.0.0
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - '='
26
25
  - !ruby/object:Gem::Version
27
- version: 1.0.0.rc5
26
+ version: 1.0.0
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: pakyow-routing
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - '='
33
32
  - !ruby/object:Gem::Version
34
- version: 1.0.0.rc5
33
+ version: 1.0.0
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - '='
40
39
  - !ruby/object:Gem::Version
41
- version: 1.0.0.rc5
40
+ version: 1.0.0
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: pakyow-support
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
45
  - - '='
47
46
  - !ruby/object:Gem::Version
48
- version: 1.0.0.rc5
47
+ version: 1.0.0
49
48
  type: :runtime
50
49
  prerelease: false
51
50
  version_requirements: !ruby/object:Gem::Requirement
52
51
  requirements:
53
52
  - - '='
54
53
  - !ruby/object:Gem::Version
55
- version: 1.0.0.rc5
54
+ version: 1.0.0
56
55
  - !ruby/object:Gem::Dependency
57
56
  name: oga
58
57
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +81,7 @@ dependencies:
82
81
  - !ruby/object:Gem::Version
83
82
  version: '3.4'
84
83
  description: Views and presentation for Pakyow
85
- email: bryan@metabahn.com
84
+ email: bryan@bryanp.org
86
85
  executables: []
87
86
  extensions: []
88
87
  extra_rdoc_files: []
@@ -90,10 +89,19 @@ files:
90
89
  - CHANGELOG.md
91
90
  - LICENSE
92
91
  - README.md
93
- - lib/pakyow/actions/presenter/auto_render.rb
92
+ - lib/pakyow/application/actions/presenter/auto_render.rb
93
+ - lib/pakyow/application/behavior/presenter/error_rendering.rb
94
+ - lib/pakyow/application/behavior/presenter/exposures.rb
95
+ - lib/pakyow/application/behavior/presenter/implicit_rendering.rb
96
+ - lib/pakyow/application/behavior/presenter/initializing.rb
97
+ - lib/pakyow/application/behavior/presenter/modes.rb
98
+ - lib/pakyow/application/behavior/presenter/versions.rb
99
+ - lib/pakyow/application/behavior/presenter/watching.rb
100
+ - lib/pakyow/application/config/presenter.rb
101
+ - lib/pakyow/application/helpers/presenter/rendering.rb
94
102
  - lib/pakyow/generators/presenter/presenter_generator.rb
95
103
  - lib/pakyow/generators/presenter/templates/presenter.rb.tt
96
- - lib/pakyow/plugin/helpers/rendering.rb
104
+ - lib/pakyow/plugin/helpers/presenter/rendering.rb
97
105
  - lib/pakyow/presenter.rb
98
106
  - lib/pakyow/presenter/attributes.rb
99
107
  - lib/pakyow/presenter/attributes/attribute.rb
@@ -101,14 +109,6 @@ files:
101
109
  - lib/pakyow/presenter/attributes/hash.rb
102
110
  - lib/pakyow/presenter/attributes/set.rb
103
111
  - lib/pakyow/presenter/attributes/string.rb
104
- - lib/pakyow/presenter/behavior/config.rb
105
- - lib/pakyow/presenter/behavior/error_rendering.rb
106
- - lib/pakyow/presenter/behavior/exposures.rb
107
- - lib/pakyow/presenter/behavior/implicit_rendering.rb
108
- - lib/pakyow/presenter/behavior/initializing.rb
109
- - lib/pakyow/presenter/behavior/modes.rb
110
- - lib/pakyow/presenter/behavior/versions.rb
111
- - lib/pakyow/presenter/behavior/watching.rb
112
112
  - lib/pakyow/presenter/binder.rb
113
113
  - lib/pakyow/presenter/binding_parts.rb
114
114
  - lib/pakyow/presenter/component.rb
@@ -117,7 +117,6 @@ files:
117
117
  - lib/pakyow/presenter/errors.rb
118
118
  - lib/pakyow/presenter/framework.rb
119
119
  - lib/pakyow/presenter/front_matter_parser.rb
120
- - lib/pakyow/presenter/helpers/rendering.rb
121
120
  - lib/pakyow/presenter/presentable.rb
122
121
  - lib/pakyow/presenter/presenter.rb
123
122
  - lib/pakyow/presenter/presenters/endpoint.rb
@@ -153,7 +152,7 @@ files:
153
152
  - lib/string_doc/meta_attributes.rb
154
153
  - lib/string_doc/meta_node.rb
155
154
  - lib/string_doc/node.rb
156
- homepage: https://pakyow.org
155
+ homepage: https://pakyow.com
157
156
  licenses:
158
157
  - LGPL-3.0
159
158
  metadata: {}
@@ -168,9 +167,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
167
  version: 2.5.0
169
168
  required_rubygems_version: !ruby/object:Gem::Requirement
170
169
  requirements:
171
- - - ">"
170
+ - - ">="
172
171
  - !ruby/object:Gem::Version
173
- version: 1.3.1
172
+ version: '0'
174
173
  requirements: []
175
174
  rubygems_version: 3.0.3
176
175
  signing_key:
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pakyow
4
- module Actions
5
- module Presenter
6
- # Renders a view in the case a controller wasn't called.
7
- #
8
- class AutoRender
9
- def call(connection)
10
- connection.app.isolated(:Renderer).render_implicitly(connection)
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- class Plugin
7
- module Helpers
8
- module Rendering
9
- extend Support::Extension
10
-
11
- prepend_methods do
12
- def render(view_path = nil, as: nil, modes: [:default])
13
- super(File.join(@connection.app.class.mount_path, view_path), as: as, modes: modes)
14
- rescue Presenter::UnknownPage
15
- # Try rendering the view from the app.
16
- #
17
- connection = @connection.app.parent.isolated(:Connection).from_connection(
18
- @connection, :@app => @connection.app.parent
19
- )
20
-
21
- connection.app.isolated(:Renderer).render(
22
- connection,
23
- view_path: view_path,
24
- presenter_path: as,
25
- modes: modes
26
- )
27
- end
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cgi"
4
-
5
- require "redcarpet"
6
-
7
- require "pakyow/support/bindable"
8
- require "pakyow/support/extension"
9
-
10
- require "pakyow/error"
11
-
12
- module Pakyow
13
- module Presenter
14
- module Behavior
15
- module ErrorRendering
16
- extend Support::Extension
17
-
18
- # @api private
19
- def self.render_error(error, context)
20
- context.respond_to :html do
21
- if Pakyow.env?(:production)
22
- context.render "/500"
23
- else
24
- unless error.is_a?(Pakyow::Error)
25
- error = Pakyow::Error.build(error)
26
- end
27
-
28
- error.extend Support::Bindable
29
- context.expose :pw_error, error
30
- context.render "/development/500"
31
- end
32
- end
33
- end
34
-
35
- apply_extension do
36
- handle 404 do
37
- respond_to :html do
38
- render "/404"
39
- end
40
- end
41
-
42
- handle 500 do |error|
43
- ErrorRendering.render_error(error, self)
44
- end
45
-
46
- handle UnknownPage, as: 404 do |error|
47
- if Pakyow.env?(:production)
48
- trigger 404
49
- else
50
- ErrorRendering.render_error(error, self)
51
- end
52
- end
53
-
54
- handle ImplicitRenderingError, as: 404 do |error|
55
- if Pakyow.env?(:production)
56
- trigger 404
57
- else
58
- ErrorRendering.render_error(error, self)
59
- end
60
- end
61
-
62
- binder :pw_error do
63
- def message
64
- html_safe(markdown.render(format(object.message)))
65
- end
66
-
67
- def contextual_message
68
- if object.respond_to?(:contextual_message)
69
- html_safe(markdown.render(format(object.contextual_message)))
70
- else
71
- nil
72
- end
73
- end
74
-
75
- def details
76
- html_safe(markdown.render(format(object.details)))
77
- end
78
-
79
- def backtrace
80
- html_safe(object.condensed_backtrace.to_a.map { |line|
81
- CGI.escape_html(line)
82
- }.join("<br>"))
83
- end
84
-
85
- def link
86
- part :href do
87
- object.url
88
- end
89
-
90
- part :content do
91
- object.url
92
- end
93
- end
94
-
95
- private
96
-
97
- def markdown
98
- @markdown ||= Redcarpet::Markdown.new(
99
- Redcarpet::Render::HTML.new({})
100
- )
101
- end
102
-
103
- def format(string)
104
- string = string.dup
105
-
106
- # Replace `foo' with `foo` to render as inline code.
107
- #
108
- string.dup.scan(/`([^']*)'/).each do |match|
109
- string.gsub!("`#{match[0]}'", "`#{match[0]}`")
110
- end
111
-
112
- # Format object references as inline code.
113
- #
114
- string.dup.scan(/#<(.*)>/).each do |match|
115
- string.gsub!("#<#{match[0]}>", "`#<#{match[0]}>`")
116
- end
117
-
118
- string
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Presenter
7
- module Behavior
8
- module Exposures
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- unless ancestors.include?(Plugin)
13
- # Copy exposures from the plugin renderer.
14
- #
15
- after "load.plugins" do
16
- plugs.each do |plug|
17
- plug.isolated(:Renderer).__expose_fns.each do |fn|
18
- isolated(:Renderer).send(:expose) do |connection|
19
- fn.call(connection, plug)
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Presenter
7
- module Behavior
8
- # Performs a render if a controller is called but doesn't explicitly render.
9
- #
10
- module ImplicitRendering
11
- extend Support::Extension
12
-
13
- apply_extension do
14
- after :dispatch, :implicit_render do
15
- connection.app.isolated(:Renderer).render_implicitly(connection)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- require "pakyow/plugin"
6
-
7
- module Pakyow
8
- module Presenter
9
- module Behavior
10
- module Initializing
11
- extend Support::Extension
12
-
13
- apply_extension do
14
- unless ancestors.include?(Plugin)
15
- after "initialize", "initialize.presenter", priority: :high do
16
- state(:templates) << Templates.new(
17
- :default,
18
- config.presenter.path,
19
- processor: ProcessorCaller.new(
20
- state(:processor).map { |processor|
21
- processor.new(self)
22
- }
23
- )
24
- )
25
-
26
- state(:templates) << Templates.new(:errors, File.join(File.expand_path("../../../", __FILE__), "views", "errors"))
27
- end
28
-
29
- after "load.plugins" do
30
- # Load plugin frontend after the app so that app has priority.
31
- #
32
- @plugs.each(&:load_frontend)
33
- end
34
- end
35
-
36
- # Build presenter classes for compound components.
37
- #
38
- after "initialize", priority: :high do
39
- state(:templates).each do |templates|
40
- templates.each do |template|
41
- template.object.each_significant_node(:component, descend: true) do |node|
42
- if node.label(:components).count > 1
43
- component_classes = node.label(:components).each_with_object([]) { |component_label, arr|
44
- component_class = state(:component).find { |component|
45
- component.__object_name.name == component_label[:name]
46
- }
47
-
48
- if component_class
49
- arr << component_class
50
- end
51
- }
52
-
53
- if component_classes.count > 1
54
- state(:presenter) << Renderer::Behavior::RenderComponents.find_or_build_compound_presenter(
55
- self, component_classes
56
- )
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Presenter
7
- module Behavior
8
- module Modes
9
- # @api private
10
- class ModeCallContext
11
- def initialize(connection)
12
- @connection = connection
13
- end
14
- end
15
-
16
- extend Support::Extension
17
-
18
- attr_accessor :__ui_modes
19
-
20
- def mode(name, &block)
21
- @__ui_modes[name.to_sym] = wrap_mode_block(block)
22
- end
23
-
24
- private def wrap_mode_block(block)
25
- if is_a?(Plugin)
26
- wrap_mode_block_for_plug(self, block)
27
- else
28
- Proc.new do |connection|
29
- isolated(:ModeCallContext).new(connection).instance_eval(&block)
30
- end
31
- end
32
- end
33
-
34
- private def wrap_mode_block_for_plug(plug, block)
35
- Proc.new do |connection|
36
- plug.helper_caller(:passive, connection, plug).instance_eval(&block)
37
- end
38
- end
39
-
40
- prepend_methods do
41
- def initialize(*)
42
- @__ui_modes = Hash[
43
- self.class.__ui_modes.map { |name, block|
44
- [name, wrap_mode_block(block)]
45
- }
46
- ]
47
-
48
- super
49
- end
50
- end
51
-
52
- apply_extension do
53
- class_state :__ui_modes, default: {}, inheritable: true
54
-
55
- after "load" do
56
- ([:html] + state(:processor).map(&:extensions).flatten).uniq.each do |extension|
57
- config.process.watched_paths << File.join(config.presenter.path, "**/*.#{extension}")
58
- end
59
- end
60
-
61
- isolate ModeCallContext
62
-
63
- on "load" do
64
- self.class.include_helpers :passive, isolated(:ModeCallContext)
65
- end
66
-
67
- if ancestors.include?(Plugin)
68
- # Copy ui modes from other plugins to this plugin.
69
- #
70
- after "load" do
71
- parent.plugs.each do |plug|
72
- plug.__ui_modes.each do |mode, block|
73
- unless @__ui_modes.key?(mode)
74
- plug_namespace = plug.class.__object_name.namespace.parts.last
75
-
76
- full_mode = if plug_namespace == :default
77
- :"@#{plug.class.plugin_name}.#{mode}"
78
- else
79
- :"@#{plug.class.plugin_name}(#{plug_namespace}).#{mode}"
80
- end
81
-
82
- @__ui_modes[full_mode] = block
83
- end
84
- end
85
- end
86
- end
87
- else
88
- # Copy ui modes from plugins to the app.
89
- #
90
- after "load.plugins" do
91
- plugs.each do |plug|
92
- plug.__ui_modes.each do |mode, block|
93
- unless @__ui_modes.key?(mode)
94
- plug_namespace = plug.class.__object_name.namespace.parts.last
95
-
96
- full_mode = if plug_namespace == :default
97
- :"@#{plug.class.plugin_name}.#{mode}"
98
- else
99
- :"@#{plug.class.plugin_name}(#{plug_namespace}).#{mode}"
100
- end
101
-
102
- @__ui_modes[full_mode] = block
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
109
-
110
- class_methods do
111
- def mode(name, &block)
112
- @__ui_modes[name.to_sym] = block
113
- end
114
- end
115
- end
116
- end
117
- end
118
- end