rackr 0.0.60 → 0.0.62

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56bb48ce2a38e77c44d84d7ee7537b144bff11293a6162750d497a392d5a2d6d
4
- data.tar.gz: 1698e4e88202736612dfcb27d974f414eaf6dbafd62c40433fd33472b638e53e
3
+ metadata.gz: e2a5e505cf9cd59162c47caa5689648b5e1167adc6f1d02192c0cde5ca3d6514
4
+ data.tar.gz: 48a936417f8aaf814ee71bd424decca4a0e6ed3effcc121a8859ee8259d22883
5
5
  SHA512:
6
- metadata.gz: 68e05e6048d84a6fdf937d6950f15b2d19d9a510e79aaa4a2bb6e375a19fd6b16788172b66e2b3752293eca89218600b319dfd146657e40fd893a619ba7a6083
7
- data.tar.gz: 2d2cb75c23f21f1d317496e6cf066c74e20f7d13cdf199f754571ba03e77fcd5a72bf253f798fa1dd24a1c434614e8b790652bad8f53591fc374d5043ebfbdbf
6
+ metadata.gz: 4577df846e784cf1acf95afd192c2f9b2953eaf1ee15c63956ddc7164bf5843afa9701157c3db2287ab23691778c5422fe87d052e2affd3d69670c8aedfbf02b
7
+ data.tar.gz: 14c4b0192f04a78524b49f1382ba3c94c48c47e0a9f112f5949ca1dc0addbe8cec28faa8f8ec27dce318eeb4dfb67fc7c25326919d0c2a1cc787c954e68cc396
@@ -1,79 +1,68 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'html_slice'
4
-
5
3
  class Rackr
6
4
  class Router
7
5
  module Errors
8
6
  class DevHtml
9
7
  include Rackr::Action
10
- include ::HtmlSlice
11
8
 
12
9
  def call(env)
13
- html_layout do
14
- tag :head do
15
- title 'Application error'
16
- _ '<style>
17
- html * { padding:0; margin:0; }
18
- body * { padding:10px 20px; }
19
- body * * { padding:0; }
20
- body { font:small sans-serif; }
21
- body>div { border-bottom:1px solid #ddd; }
22
- h1 { font-weight:normal; }
23
- h2 { margin-bottom:.8em; }
24
- h2 span { font-size:80%; color:#666; font-weight:normal; }
25
- #summary { background: #ffc; }
26
- #summary h2 { font-weight: normal; color: #666; }
27
- pre {
28
- background: #f8f8f8;
29
- padding: 1em;
30
- margin-bottom: 1em;
31
- }
32
- </style>'
33
- end
34
- tag :body do
35
- div id: 'summary' do
36
- h1 env['error'].class.to_s
37
- if env['error'].message.size > 1000
38
- h2 "#{env['error'].message.slice(0, 1000)} ..."
39
- else
40
- h2 env['error'].message
41
- end
42
- end
43
- div id: 'backtrace' do
44
- backtrace(env)
45
- end
46
- end
47
- end
10
+ render(html: <<-HTML
11
+ <!DOCTYPE html>
12
+ <html>
13
+ <head>
14
+ <title>Application error</title>
15
+ <style>
16
+ html * { padding:0; margin:0; }
17
+ body * { padding:10px 20px; }
18
+ body * * { padding:0; }
19
+ body { font:small sans-serif; }
20
+ body>div { border-bottom:1px solid #ddd; }
21
+ h1 { font-weight:normal; }
22
+ h2 { margin-bottom:.8em; }
23
+ h2 span { font-size:80%; color:#666; font-weight:normal; }
24
+ #summary { background: #ffc; }
25
+ #summary h2 { font-weight: normal; color: #666; }
26
+ #backtrace { background: #eee; }
27
+ pre {
28
+ background: #ddd;
29
+ padding: 1em;
30
+ margin-bottom: 1em;
31
+ }
32
+ p {
33
+ font-family: monospace;
34
+ }
35
+ </style>
36
+ </head>
37
+ <body>
38
+ <div id="summary">
39
+ <h1>#{env['error'].class}</h1>
40
+ <h2>#{env['error'].message.size > 1000 ? "#{env['error'].message.slice(0, 1000)} ..." : env['error'].message}</h2>
41
+ </div>
42
+ <div id="backtrace">
43
+ #{backtrace(env)}
44
+ </div>
45
+ </body>
46
+ </html>
47
+ HTML
48
+ )
48
49
  end
49
50
 
50
51
  def backtrace(env)
51
52
  first, *tail = env['error'].backtrace
52
- h2 do
53
- _ 'Traceback '
54
- span '(innermost first)'
55
- end
56
-
57
- tag :p, first, class: 'first-p'
58
- br
53
+ traceback = String.new("<h2>Traceback <span>(innermost first)</span></h2>")
54
+ traceback << "<p class=\"first-p\">#{first}</p><br/>"
59
55
 
60
56
  line_number = extract_line_number(first)
61
- match = first.match(%r{^(/[\w/.-]+)})
57
+ match = first.match(%r{^(/[[\w/.-]]+)})
62
58
  file_path = (match ? match[1] : nil)
63
59
  unless file_path.nil?
64
- lines = []
65
- File.open(file_path) do |file|
66
- lines = file.readlines
67
- end
68
-
69
- lines.map!.with_index do |line, i|
70
- "#{i + 1}: #{line} \n"
71
- end
72
-
73
- tag :pre, slice_around_index(lines, line_number).join('').chomp
60
+ lines = File.readlines(file_path).map.with_index { |line, i| "#{i + 1}: #{line}" }
61
+ traceback << "<pre>#{slice_around_index(lines, line_number).join('')}</pre>"
74
62
  end
75
63
 
76
- tag :p, tail.join("\n")
64
+ traceback << "<p>#{tail.join("<br>")}</p>"
65
+ traceback
77
66
  end
78
67
 
79
68
  def extract_line_number(input)
@@ -89,7 +78,6 @@ class Rackr
89
78
  start_index = [index - 2, 0].max
90
79
  end_index = [index + 2, array.size - 1].min
91
80
 
92
- # Slice the array
93
81
  array[start_index..end_index]
94
82
  end
95
83
  end
data/lib/rackr.rb CHANGED
@@ -18,6 +18,11 @@ class Rackr
18
18
 
19
19
  def call(&block)
20
20
  instance_eval(&block)
21
+ puts "\n= Routes =============="
22
+ routes.each_pair { |v| p v }
23
+ puts "\n= Config =============="
24
+ puts config
25
+ puts "\n"
21
26
 
22
27
  @router
23
28
  end
@@ -61,35 +66,50 @@ class Rackr
61
66
  end
62
67
  end
63
68
 
64
- # Beta
65
- def resources(name, id:)
66
- const_name = name.to_s.capitalize
67
- id ||= :id
69
+ def resources(name, id: :id, before: [], after: [], &block)
70
+ @resource_namespace = (@resource_namespace || []).push([name.to_s.capitalize])
68
71
 
69
- scope name do
70
- get Object.const_get("Actions::#{const_name}::Index") if Object.const_defined?("Actions::#{const_name}::Index")
71
- get 'new', Object.const_get("Actions::#{const_name}::New") if Object.const_defined?("Actions::#{const_name}::New")
72
- post Object.const_get("Actions::#{const_name}::Index") if Object.const_defined?("Actions::#{const_name}::Index")
72
+ get_const = ->(type, action) do
73
+ if Object.const_defined?("#{type}::#{@resource_namespace.join('::')}::#{action}")
74
+ Object.const_get("#{type}::#{@resource_namespace.join('::')}::#{action}")
75
+ end
76
+ end
73
77
 
74
- resource_actions = proc do
75
- get Object.const_get("Actions::#{const_name}::Show") if Object.const_defined?("Actions::#{const_name}::Show")
76
- if Object.const_defined?("Actions::#{const_name}::Edit")
77
- get 'edit', Object.const_get("Actions::#{const_name}::Edit")
78
- end
79
- if Object.const_defined?("Actions::#{const_name}::Update")
80
- put Object.const_get("Actions::#{const_name}::Update")
81
- end
82
- if Object.const_defined?("Actions::#{const_name}::Delete")
83
- delete Object.const_get("Actions::#{const_name}::Delete")
84
- end
78
+ actions = {
79
+ index: { method: :get, path: nil, action: get_const.call('Actions', 'Index') },
80
+ new: { method: :get, path: 'new', action: get_const.call('Actions', 'New') },
81
+ create: { method: :post, path: nil, action: get_const.call('Actions', 'Create') },
82
+ }
83
+
84
+ actions_for_id = {
85
+ show: { method: :get, path: nil, action: get_const.call('Actions', 'Show') },
86
+ edit: { method: :get, path: "edit", action: get_const.call('Actions', 'Edit') },
87
+ update: { method: :put, path: nil, action: get_const.call('Actions', 'Update') },
88
+ delete: { method: :delete, path: nil, action: get_const.call('Actions', 'Delete') }
89
+ }
90
+
91
+ block_for_id = proc do
92
+ actions_for_id.each do |_, definition|
93
+ send(definition[:method], definition[:path], definition[:action]) if definition[:action]
85
94
  end
86
95
 
87
- if Object.const_defined?("Callbacks::#{const_name}::Assign")
88
- scope(id.to_sym, before: Object.const_get("Callbacks::#{const_name}::Assign"), &resource_actions)
96
+ instance_eval(&block) if block_given?
97
+ end
98
+
99
+ scope(name.to_s, before:, after:) do
100
+ actions.each do |_, definition|
101
+ send(definition[:method], definition[:path], definition[:action]) if definition[:action]
102
+ end
103
+
104
+ assign_callback = get_const.call('Callbacks', 'Assign')
105
+ if assign_callback
106
+ scope(id.to_sym, before: assign_callback, &block_for_id)
89
107
  else
90
- scope(id.to_sym, &resource_actions)
108
+ scope(id.to_sym, &block_for_id)
91
109
  end
92
110
  end
111
+
112
+ @resource_namespace = @resource_namespace.first(@resource_namespace.size - 1)
93
113
  end
94
114
 
95
115
  HTTP_METHODS.each do |http_method|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.60
4
+ version: 0.0.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-11 00:00:00.000000000 Z
10
+ date: 2025-10-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: erubi
@@ -57,26 +57,6 @@ dependencies:
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '4.0'
60
- - !ruby/object:Gem::Dependency
61
- name: html_slice
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: '0.0'
67
- - - "<"
68
- - !ruby/object:Gem::Version
69
- version: '1.0'
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0.0'
77
- - - "<"
78
- - !ruby/object:Gem::Version
79
- version: '1.0'
80
60
  description: A complete, simple and easy web micro-framework.
81
61
  email: hriqueft@gmail.com
82
62
  executables: []