pakyow-presenter 0.11.3 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/{pakyow-presenter/CHANGELOG.md → CHANGELOG.md} +0 -5
  3. data/LICENSE +4 -0
  4. data/{pakyow-presenter/README.md → README.md} +1 -2
  5. data/lib/pakyow/generators/presenter/presenter_generator.rb +28 -0
  6. data/lib/pakyow/generators/presenter/templates/presenter.rb.tt +2 -0
  7. data/lib/pakyow/plugin/helpers/rendering.rb +19 -0
  8. data/lib/pakyow/presenter/actions/auto_render.rb +15 -0
  9. data/lib/pakyow/presenter/attributes/attribute.rb +22 -0
  10. data/lib/pakyow/presenter/attributes/boolean.rb +24 -0
  11. data/lib/pakyow/presenter/attributes/hash.rb +89 -0
  12. data/lib/pakyow/presenter/attributes/set.rb +61 -0
  13. data/lib/pakyow/presenter/attributes/string.rb +38 -0
  14. data/lib/pakyow/presenter/attributes.rb +126 -0
  15. data/lib/pakyow/presenter/behavior/config.rb +29 -0
  16. data/lib/pakyow/presenter/behavior/error_rendering.rb +124 -0
  17. data/lib/pakyow/presenter/behavior/exposures.rb +29 -0
  18. data/lib/pakyow/presenter/behavior/implicit_rendering.rb +21 -0
  19. data/lib/pakyow/presenter/behavior/initializing.rb +37 -0
  20. data/lib/pakyow/presenter/behavior/modes.rb +117 -0
  21. data/lib/pakyow/presenter/behavior/versions.rb +71 -0
  22. data/lib/pakyow/presenter/behavior/watching.rb +21 -0
  23. data/lib/pakyow/presenter/binder.rb +115 -0
  24. data/lib/pakyow/presenter/binding_parts.rb +64 -0
  25. data/lib/pakyow/presenter/component.rb +74 -0
  26. data/lib/pakyow/presenter/composers/component.rb +78 -0
  27. data/lib/pakyow/presenter/composers/view.rb +73 -0
  28. data/lib/pakyow/presenter/errors.rb +63 -0
  29. data/lib/pakyow/presenter/framework.rb +203 -0
  30. data/lib/pakyow/presenter/front_matter_parser.rb +42 -0
  31. data/lib/pakyow/presenter/helpers/rendering.rb +18 -0
  32. data/lib/pakyow/presenter/presentable.rb +28 -0
  33. data/lib/pakyow/presenter/presentable_error.rb +19 -0
  34. data/lib/pakyow/presenter/presenter.rb +766 -0
  35. data/lib/pakyow/presenter/presenters/endpoint.rb +158 -0
  36. data/lib/pakyow/presenter/presenters/form.rb +522 -0
  37. data/lib/pakyow/presenter/processor.rb +61 -0
  38. data/lib/pakyow/presenter/renderable.rb +28 -0
  39. data/lib/pakyow/presenter/renderer.rb +269 -0
  40. data/lib/pakyow/presenter/rendering/actions/cleanup_prototype_nodes.rb +21 -0
  41. data/lib/pakyow/presenter/rendering/actions/cleanup_unbound_bindings.rb +35 -0
  42. data/lib/pakyow/presenter/rendering/actions/create_template_nodes.rb +27 -0
  43. data/lib/pakyow/presenter/rendering/actions/insert_prototype_bar.rb +101 -0
  44. data/lib/pakyow/presenter/rendering/actions/install_authenticity.rb +42 -0
  45. data/lib/pakyow/presenter/rendering/actions/place_in_mode.rb +56 -0
  46. data/lib/pakyow/presenter/rendering/actions/render_components.rb +279 -0
  47. data/lib/pakyow/presenter/rendering/actions/set_page_title.rb +35 -0
  48. data/lib/pakyow/presenter/rendering/actions/setup_endpoints.rb +62 -0
  49. data/lib/pakyow/presenter/rendering/actions/setup_forms.rb +174 -0
  50. data/lib/pakyow/presenter/significant_nodes.rb +309 -0
  51. data/lib/pakyow/presenter/templates.rb +229 -0
  52. data/lib/pakyow/presenter/versioned_view.rb +209 -0
  53. data/lib/pakyow/presenter/view.rb +586 -0
  54. data/lib/pakyow/presenter/views/form.rb +58 -0
  55. data/lib/pakyow/presenter/views/layout.rb +32 -0
  56. data/lib/pakyow/presenter/views/page.rb +72 -0
  57. data/lib/pakyow/presenter/views/partial.rb +28 -0
  58. data/lib/pakyow/presenter.rb +33 -0
  59. data/lib/pakyow/views/errors/layouts/development_error.html +102 -0
  60. data/lib/pakyow/views/errors/layouts/production_error.html +27 -0
  61. data/lib/pakyow/views/errors/pages/404.html +12 -0
  62. data/lib/pakyow/views/errors/pages/500.html +12 -0
  63. data/lib/pakyow/views/errors/pages/development/500.html +39 -0
  64. data/lib/string_doc/attributes.rb +109 -0
  65. data/lib/string_doc/meta_attributes.rb +48 -0
  66. data/lib/string_doc/meta_node.rb +328 -0
  67. data/lib/string_doc/node.rb +377 -0
  68. data/lib/string_doc.rb +642 -0
  69. metadata +95 -75
  70. data/pakyow-presenter/LICENSE +0 -20
  71. data/pakyow-presenter/lib/pakyow/presenter/attributes.rb +0 -228
  72. data/pakyow-presenter/lib/pakyow/presenter/base.rb +0 -38
  73. data/pakyow-presenter/lib/pakyow/presenter/binder.rb +0 -116
  74. data/pakyow-presenter/lib/pakyow/presenter/binder_set.rb +0 -94
  75. data/pakyow-presenter/lib/pakyow/presenter/binding_eval.rb +0 -37
  76. data/pakyow-presenter/lib/pakyow/presenter/config/presenter.rb +0 -42
  77. data/pakyow-presenter/lib/pakyow/presenter/container.rb +0 -6
  78. data/pakyow-presenter/lib/pakyow/presenter/doc_helpers.rb +0 -17
  79. data/pakyow-presenter/lib/pakyow/presenter/exceptions.rb +0 -11
  80. data/pakyow-presenter/lib/pakyow/presenter/ext/app.rb +0 -33
  81. data/pakyow-presenter/lib/pakyow/presenter/ext/call_context.rb +0 -28
  82. data/pakyow-presenter/lib/pakyow/presenter/helpers.rb +0 -46
  83. data/pakyow-presenter/lib/pakyow/presenter/page.rb +0 -110
  84. data/pakyow-presenter/lib/pakyow/presenter/partial.rb +0 -6
  85. data/pakyow-presenter/lib/pakyow/presenter/presenter.rb +0 -232
  86. data/pakyow-presenter/lib/pakyow/presenter/string_doc.rb +0 -380
  87. data/pakyow-presenter/lib/pakyow/presenter/string_doc_parser.rb +0 -144
  88. data/pakyow-presenter/lib/pakyow/presenter/string_doc_renderer.rb +0 -18
  89. data/pakyow-presenter/lib/pakyow/presenter/template.rb +0 -51
  90. data/pakyow-presenter/lib/pakyow/presenter/view.rb +0 -541
  91. data/pakyow-presenter/lib/pakyow/presenter/view_collection.rb +0 -330
  92. data/pakyow-presenter/lib/pakyow/presenter/view_composer.rb +0 -237
  93. data/pakyow-presenter/lib/pakyow/presenter/view_context.rb +0 -111
  94. data/pakyow-presenter/lib/pakyow/presenter/view_store.rb +0 -262
  95. data/pakyow-presenter/lib/pakyow/presenter/view_store_loader.rb +0 -43
  96. data/pakyow-presenter/lib/pakyow/presenter/view_version.rb +0 -113
  97. data/pakyow-presenter/lib/pakyow/presenter.rb +0 -8
  98. data/pakyow-presenter/lib/pakyow/views/errors/404.erb +0 -26
  99. data/pakyow-presenter/lib/pakyow/views/errors/500.erb +0 -23
  100. data/pakyow-presenter/lib/pakyow-presenter.rb +0 -1
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Pakyow
6
+ module Presenter
7
+ class Page < View
8
+ DEFAULT_CONTAINER = :main
9
+
10
+ attr_reader :name, :path
11
+
12
+ class << self
13
+ def load(path, content: nil, **args)
14
+ self.new(File.basename(path, ".*").to_sym, content || File.read(path), **args, path: path)
15
+ end
16
+ end
17
+
18
+ def initialize(name, html = "", path: nil, info: {}, **args)
19
+ @containers = {}
20
+ parse_content(html)
21
+ @name, @path = name, path
22
+ info[:layout] ||= :default
23
+ super(html, info: info, **args)
24
+ end
25
+
26
+ def initialize_copy(_)
27
+ super
28
+
29
+ @containers = Hash[@containers.map { |key, value|
30
+ [key, value.dup]
31
+ }]
32
+ end
33
+
34
+ def content(container)
35
+ container = container.to_sym
36
+
37
+ if container == DEFAULT_CONTAINER
38
+ @object
39
+ elsif @containers.key?(container)
40
+ @containers[container].object
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
46
+ def mixin(partials)
47
+ super
48
+
49
+ @containers.values.each do |view|
50
+ view.mixin(partials)
51
+ end
52
+ end
53
+
54
+ def container_views
55
+ [View.from_object(@object)].concat(@containers.values)
56
+ end
57
+
58
+ protected
59
+
60
+ WITHIN_REGEX = /<!--\s*@within\s*([a-zA-Z0-9\-_]*)\s*-->(.*?)<!--\s*\/within\s*-->/m
61
+
62
+ def parse_content(html)
63
+ html.scan(WITHIN_REGEX) do |match|
64
+ container_name = match[0].to_sym
65
+ @containers[container_name] = View.from_object(StringDoc.new(match[1]))
66
+ end
67
+
68
+ html.gsub!(WITHIN_REGEX, "")
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pakyow
4
+ module Presenter
5
+ class Partial < View
6
+ attr_accessor :name
7
+
8
+ class << self
9
+ def load(path, content: nil, **args)
10
+ name = File.basename(path, ".*")
11
+ name = name[1..-1] if name.start_with?("_")
12
+ self.new(name.to_sym, content || File.read(path), **args)
13
+ end
14
+
15
+ def from_object(name, object)
16
+ super(object).tap do |instance|
17
+ instance.instance_variable_set(:@name, name)
18
+ end
19
+ end
20
+ end
21
+
22
+ def initialize(name, html = "", **args)
23
+ @name = name
24
+ super(html, **args)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/silenceable"
4
+ Pakyow::Support::Silenceable.silence_warnings do
5
+ require "oga"
6
+ end
7
+
8
+ require "pakyow/presenter/framework"
9
+ require "pakyow/presenter/presenter"
10
+
11
+ require "pakyow/presenter/significant_nodes"
12
+
13
+ require "pakyow/presenter/view"
14
+ require "pakyow/presenter/attributes"
15
+ require "pakyow/presenter/versioned_view"
16
+
17
+ require "pakyow/presenter/templates"
18
+ require "pakyow/presenter/front_matter_parser"
19
+ require "pakyow/presenter/processor"
20
+ require "pakyow/presenter/binder"
21
+ require "pakyow/presenter/binding_parts"
22
+ require "pakyow/presenter/component"
23
+
24
+ require "pakyow/presenter/views/form"
25
+ require "pakyow/presenter/views/layout"
26
+ require "pakyow/presenter/views/page"
27
+ require "pakyow/presenter/views/partial"
28
+
29
+ require "pakyow/presenter/presenters/form"
30
+
31
+ require "pakyow/presenter/errors"
32
+
33
+ require "pakyow/presenter/actions/auto_render"
@@ -0,0 +1,102 @@
1
+ ---
2
+ title: "{pw_error.name}"
3
+ ---
4
+
5
+ <html lang="en">
6
+ <head>
7
+ <title></title>
8
+
9
+ <meta charset="utf-8">
10
+ <meta name="viewport" content="initial-scale=1, minimum-scale=1, width=device-width">
11
+
12
+ <style>
13
+ * {
14
+ font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
15
+ font-size: 13px;
16
+ line-height: 20px;
17
+ color: #111;
18
+ line-height: 2.0rem;
19
+ }
20
+ body {
21
+ background: #fff;
22
+ }
23
+ main {
24
+ max-width: 800px;
25
+ padding: 100px 0;
26
+ margin: auto;
27
+ }
28
+ code {
29
+ white-space: nowrap;
30
+ display: block;
31
+ overflow: auto;
32
+ background: #f9f9f9;
33
+ padding: 5px 15px;
34
+ box-shadow: 0.30rem 0.30rem #ff8b6c;
35
+ line-height: 1.5rem;
36
+ color: #333;
37
+ }
38
+ code, code pre {
39
+ font-family: monospace;
40
+ font-size: 13px;
41
+ }
42
+ code pre, pre code {
43
+ white-space: pre;
44
+ margin: 0;
45
+ }
46
+ p code {
47
+ padding: 3px 5px;
48
+ font-size: 13.5px;
49
+ display: inline;
50
+ box-shadow: none;
51
+ border: 0;
52
+ }
53
+ hr {
54
+ border: 0;
55
+ height: 3px;
56
+ background: #eaeaea;
57
+ margin: 30px 0;
58
+ }
59
+ h1 {
60
+ font-size: 30px;
61
+ margin-bottom: 30px;
62
+ }
63
+ h2 {
64
+ font-size: 13px;
65
+ text-transform: uppercase;
66
+ margin-top: 30px;
67
+ }
68
+ a {
69
+ display: inline-block;
70
+ padding: 5px;
71
+ background: #156eed;
72
+ font-weight: bold;
73
+ color: #fff;
74
+ text-decoration: none;
75
+ font-size: 12px;
76
+ line-height: 14px;
77
+ }
78
+ a:hover {
79
+ opacity: 0.9;
80
+ }
81
+ ul {
82
+ margin-top: 15px;
83
+ margin-bottom: 30px;
84
+ padding-left: 45px;
85
+ }
86
+ header p {
87
+ font-size: 15px;
88
+ font-weight: 500;
89
+ }
90
+ header p::before {
91
+ content: "\203a\a0\a0";
92
+ display: inline-block;
93
+ padding-left: 30px;
94
+ }
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <main>
99
+ <!-- @container -->
100
+ </main>
101
+ </body>
102
+ </html>
@@ -0,0 +1,27 @@
1
+ <html lang="en">
2
+ <head>
3
+ <title></title>
4
+
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="initial-scale=1, minimum-scale=1, width=device-width">
7
+
8
+ <style>
9
+ * {
10
+ font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
11
+ font-size: 15px;
12
+ color: #111;
13
+ }
14
+ main {
15
+ max-width: 500px;
16
+ padding: 0 30px;
17
+ margin: auto;
18
+ margin-top: 30%;
19
+ }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <main>
24
+ <!-- @container -->
25
+ </main>
26
+ </body>
27
+ </html>
@@ -0,0 +1,12 @@
1
+ ---
2
+ layout: production_error
3
+ title: 404 (Not Found)
4
+ ---
5
+
6
+ <p>
7
+ <strong>404 (Not Found)</strong>
8
+ </p>
9
+
10
+ <p>
11
+ The URL you requested was not found.
12
+ </p>
@@ -0,0 +1,12 @@
1
+ ---
2
+ layout: production_error
3
+ title: 500 (Server Error)
4
+ ---
5
+
6
+ <p>
7
+ <strong>500 (Server Error)</strong>
8
+ </p>
9
+
10
+ <p>
11
+ Something went wrong.
12
+ </p>
@@ -0,0 +1,39 @@
1
+ ---
2
+ layout: development_error
3
+ ---
4
+
5
+ <article binding="pw_error">
6
+ <header>
7
+ <h1 binding="name">
8
+ Error Class
9
+ </h1>
10
+
11
+ <section binding="message">
12
+ Error message goes here.
13
+ </section>
14
+ </header>
15
+
16
+ <hr>
17
+
18
+ <section binding="contextual_message">
19
+ <p>
20
+ Contextual error details go here.
21
+ </p>
22
+ </section>
23
+
24
+ <hr>
25
+
26
+ <section binding="details">
27
+ <p>
28
+ Details go here.
29
+ </p>
30
+ </section>
31
+
32
+ <h2>
33
+ Backtrace:
34
+ </h2>
35
+
36
+ <code>
37
+ <pre binding="backtrace"></pre>
38
+ </code>
39
+ </article>
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ class StringDoc
6
+ # String-based XML attributes.
7
+ #
8
+ class Attributes
9
+ OPENING = '="'
10
+ CLOSING = '"'
11
+ SPACING = " "
12
+
13
+ include Pakyow::Support::SafeStringHelpers
14
+
15
+ extend Forwardable
16
+
17
+ # @!method keys
18
+ # Returns the attribute keys.
19
+ #
20
+ # @!method key?
21
+ # Returns true if value is a key.
22
+ #
23
+ # @!method []
24
+ # Looks up a value for an attribute.
25
+ #
26
+ # @!method []=
27
+ # Sets a value for an attribute.
28
+ #
29
+ # @!method delete
30
+ # Removes an attribute by name.
31
+ #
32
+ # @!method each
33
+ # Yields each attribute.
34
+ #
35
+ def_delegators :@attributes_hash, :keys, :each
36
+
37
+ def initialize(attributes_hash = {})
38
+ @attributes_hash = Hash[attributes_hash.map { |key, value|
39
+ [key.to_s, value]
40
+ }]
41
+ end
42
+
43
+ def []=(key, value)
44
+ @attributes_hash[key.to_s] = value
45
+ end
46
+
47
+ def [](key)
48
+ @attributes_hash[key.to_s]
49
+ end
50
+
51
+ def delete(key)
52
+ @attributes_hash.delete(key.to_s)
53
+ end
54
+
55
+ def key?(key)
56
+ @attributes_hash.key?(key.to_s)
57
+ end
58
+
59
+ def to_s
60
+ string = @attributes_hash.compact.map { |name, value|
61
+ name + OPENING + value.to_s + CLOSING
62
+ }.join(SPACING)
63
+
64
+ if string.empty?
65
+ string
66
+ else
67
+ SPACING + string
68
+ end
69
+ end
70
+
71
+ def each_string
72
+ if @attributes_hash.empty?
73
+ yield ""
74
+ else
75
+ @attributes_hash.each do |name, value|
76
+ yield SPACING
77
+ yield name
78
+ yield OPENING
79
+ yield value.to_s
80
+ yield CLOSING
81
+ end
82
+ end
83
+ end
84
+
85
+ def ==(other)
86
+ other.is_a?(Attributes) && @attributes_hash == other.attributes_hash
87
+ end
88
+
89
+ # @api private
90
+ attr_reader :attributes_hash
91
+
92
+ # @api private
93
+ def initialize_copy(_)
94
+ hash = {}
95
+ @attributes_hash.each do |key, value|
96
+ hash[key] = value.dup
97
+ end
98
+
99
+ @attributes_hash = hash
100
+ end
101
+
102
+ # @api private
103
+ def wrap
104
+ @attributes_hash.each do |key, value|
105
+ @attributes_hash[key] = yield(value, key)
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StringDoc
4
+ # Lets two or more node's attributes to be manipulated together. Used by {StringDoc::MetaNode}.
5
+ #
6
+ class MetaAttributes
7
+ def initialize(attributes)
8
+ @attributes = attributes
9
+ end
10
+
11
+ def []=(key, value)
12
+ @attributes.each do |attributes|
13
+ attributes[key] = value
14
+ end
15
+ end
16
+
17
+ def [](key)
18
+ @attributes[0][key]
19
+ end
20
+
21
+ def delete(key)
22
+ @attributes.each do |attributes|
23
+ attributes.delete(key)
24
+ end
25
+ end
26
+
27
+ def key?(key)
28
+ @attributes.any? { |attributes|
29
+ attributes.key?(key)
30
+ }
31
+ end
32
+
33
+ def each(&block)
34
+ @attributes.each do |attributes|
35
+ attributes.each(&block)
36
+ end
37
+ end
38
+
39
+ # @api private
40
+ def wrap
41
+ @attributes.each do |attributes|
42
+ attributes.each do |key, value|
43
+ yield value, key
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end