leanweb 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/leanweb +13 -9
- data/contrib/lib/hawese.rb +32 -7
- data/contrib/lib/lean_mail.rb +6 -4
- data/contrib/lib/leanweb/controller_mixins/render_with_layout.rb +24 -21
- data/contrib/lib/rack/session/json_file.rb +4 -3
- data/lib/leanweb/app.rb +3 -3
- data/lib/leanweb/controller.rb +10 -6
- data/lib/leanweb/helpers.rb +3 -3
- data/lib/leanweb/route.rb +3 -3
- data/lib/leanweb/version.rb +1 -1
- data/lib/leanweb.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54fc1b8b4dff318eb3ccc51e8f0862706c0b8de9879dadf403580f00a224b9df
|
4
|
+
data.tar.gz: e2a5d17a9f7a2f13f0cb2983031f91127387021a26d70a7bc91e0722ffb19bf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0563e596c38aefdd7af7150ed4f87dbbb55c6bee5459d397574e5fb1da18fe31e5091d6f8346e952729118fed9fda8f6e0b3f2579e0b39fc54d426cee76b81ed
|
7
|
+
data.tar.gz: 579991147e69766158a1168d28ec58f8da90a94ad4383e2fe8001b15cc4460895892600d53968e063e067a7be2c12347f25e37ec94cb2237e5adc32c04333a1a
|
data/bin/leanweb
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
5
5
|
#
|
6
6
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
7
|
-
# General Public License version 3 with permissions
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# General Public License version 3 with additional permissions.
|
8
|
+
# You should have received a copy of this license along with the software. If
|
9
|
+
# not, see <https://gnu.org/licenses/>.
|
10
10
|
|
11
11
|
require 'fileutils'
|
12
12
|
require 'leanweb'
|
@@ -21,10 +21,10 @@ files = [
|
|
21
21
|
|
22
22
|
source 'https://rubygems.org'
|
23
23
|
|
24
|
-
gem 'leanweb', '~> #{LeanWeb::VERSION}'
|
25
24
|
gem 'haml', '~> 5.2.2'
|
26
|
-
gem '
|
25
|
+
gem 'leanweb', '~> #{LeanWeb::VERSION}'
|
27
26
|
gem 'puma'
|
27
|
+
gem 'rake'
|
28
28
|
RUBY
|
29
29
|
}, {
|
30
30
|
filename: 'config.ru',
|
@@ -36,10 +36,15 @@ files = [
|
|
36
36
|
|
37
37
|
if ENV['RACK_ENV'] == 'development'
|
38
38
|
use(Rack::Reloader, 0)
|
39
|
-
|
39
|
+
app = Rack::Cascade.new([
|
40
|
+
LeanWeb::App.new(ROUTES),
|
41
|
+
Rack::Files.new(LeanWeb::PUBLIC_PATH)
|
42
|
+
])
|
43
|
+
else
|
44
|
+
app = LeanWeb::App.new(ROUTES)
|
40
45
|
end
|
41
46
|
|
42
|
-
run
|
47
|
+
run app
|
43
48
|
RUBY
|
44
49
|
}, {
|
45
50
|
filename: 'routes.rb',
|
@@ -107,9 +112,8 @@ begin
|
|
107
112
|
path = ARGV[1] || '.'
|
108
113
|
FileUtils.mkdir_p(path)
|
109
114
|
FileUtils.cd(path)
|
110
|
-
FileUtils.mkdir_p(['
|
115
|
+
FileUtils.mkdir_p(['src/controllers', 'src/views'])
|
111
116
|
files.each{ |file| File.write(file[:filename], file[:content]) }
|
112
|
-
`git init`
|
113
117
|
`bundle config --local path vendor/bundle`
|
114
118
|
`bundle install`
|
115
119
|
puts("Project '#{File.basename(Dir.getwd)}' successfully created.")
|
data/contrib/lib/hawese.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
require 'json'
|
11
11
|
require 'net/http'
|
@@ -20,6 +20,7 @@ require 'uri'
|
|
20
20
|
# - HAWESE_RETURN_URL defaults to `LEANWEB_ENDPOINT/checkout`.
|
21
21
|
# - HAWESE_ENDPOINT
|
22
22
|
# - HAWESE_ORIGIN
|
23
|
+
# - HAWESE_AUTH_TOKEN
|
23
24
|
class Hawese
|
24
25
|
class << self
|
25
26
|
ENDPOINT = ENV.fetch('HAWESE_ENDPOINT')
|
@@ -30,7 +31,7 @@ class Hawese
|
|
30
31
|
|
31
32
|
def payment_methods(country = '*', currency = nil)
|
32
33
|
endpoint = String.new(
|
33
|
-
"#{ENDPOINT}/gateways/payment-methods/purchase?country=#{country}"
|
34
|
+
"#{ENDPOINT}/#{ORIGIN}/gateways/payment-methods/purchase?country=#{country}"
|
34
35
|
)
|
35
36
|
endpoint << "¤cy=#{currency}" if currency
|
36
37
|
uri = URI(endpoint)
|
@@ -38,14 +39,13 @@ class Hawese
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def gateway_schema(gateway, query_params, schema = 'purchase')
|
41
|
-
uri = URI("#{ENDPOINT}/gateways/#{gateway}/schemas/#{schema}")
|
42
|
+
uri = URI("#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}/schemas/#{schema}")
|
42
43
|
uri.query = URI.encode_www_form(query_params)
|
43
44
|
JSON.parse(Net::HTTP.get(uri), symbolize_names: true)
|
44
45
|
end
|
45
46
|
|
46
47
|
def purchase(gateway, fields)
|
47
|
-
|
48
|
-
uri = URI("#{ENDPOINT}/gateways/#{gateway}/purchase")
|
48
|
+
uri = URI("#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}/purchase")
|
49
49
|
uri.query = URI.encode_www_form(return_url: RETURN_URL)
|
50
50
|
response = Net::HTTP.post(
|
51
51
|
uri,
|
@@ -55,6 +55,21 @@ class Hawese
|
|
55
55
|
JSON.parse(response.body, symbolize_names: true)
|
56
56
|
end
|
57
57
|
|
58
|
+
def receipt(gateway, payment_uuid, fields = {})
|
59
|
+
uri = URI(
|
60
|
+
"#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}/receipt/#{payment_uuid}"
|
61
|
+
)
|
62
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
63
|
+
req = Net::HTTP::Post.new(uri, {
|
64
|
+
'Authorization' => "Bearer #{ENV.fetch('HAWESE_AUTH_TOKEN')}",
|
65
|
+
'Content-Type' => 'application/json'
|
66
|
+
})
|
67
|
+
req.body = fields.to_json
|
68
|
+
response = http.request(req)
|
69
|
+
receipt_process_response(response)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
58
73
|
def purchase_from_schema(gateway, schema)
|
59
74
|
purchase(gateway, fields_to_schema_defaults(schema))
|
60
75
|
end
|
@@ -82,5 +97,15 @@ class Hawese
|
|
82
97
|
end
|
83
98
|
fields
|
84
99
|
end
|
100
|
+
|
101
|
+
def receipt_process_response(response)
|
102
|
+
response_body = JSON.parse(response.body, symbolize_names: true)
|
103
|
+
|
104
|
+
case response.code
|
105
|
+
when '401' then raise(response_body)
|
106
|
+
when '200' then response_body
|
107
|
+
else raise(response_body[:error][:message])
|
108
|
+
end
|
109
|
+
end
|
85
110
|
end
|
86
111
|
end
|
data/contrib/lib/lean_mail.rb
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
|
+
require 'base64'
|
10
11
|
require 'net/smtp'
|
11
12
|
require 'securerandom'
|
12
13
|
require 'socket'
|
@@ -42,9 +43,10 @@ module LeanMail
|
|
42
43
|
|
43
44
|
def to_s
|
44
45
|
<<~MAIL
|
46
|
+
Content-type: text/plain; charset=UTF-8
|
45
47
|
From: #{@from}
|
46
48
|
To: #{to.instance_of?(Array) ? to.join(', ') : to}
|
47
|
-
Subject:
|
49
|
+
Subject: =?UTF-8?B?#{Base64.strict_encode64(subject)}?=
|
48
50
|
Date: #{Time.new.rfc2822}
|
49
51
|
Message-Id: <#{SecureRandom.uuid}@#{Socket.gethostname}>
|
50
52
|
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
|
11
11
|
module LeanWeb
|
@@ -22,6 +22,7 @@ module LeanWeb
|
|
22
22
|
# All paths used on parameters can be relative to {VIEW_PATH} or absolute.
|
23
23
|
#
|
24
24
|
# @param path [String] Path to file to rendered.
|
25
|
+
# @param locals [Hash] Local variables for rendered document.
|
25
26
|
# @param title [String] `@content_for[:title]` content.
|
26
27
|
# @param head [Hash] Things to be inserted on `@content_for[:head]`.
|
27
28
|
# @option head [String|Array] :js Javascript file path(s).
|
@@ -39,6 +40,7 @@ module LeanWeb
|
|
39
40
|
# @yield On dynamic templates (such as Haml and ERB) you can yield.
|
40
41
|
def render_with_layout( # rubocop:disable Metrics/ParameterLists
|
41
42
|
path,
|
43
|
+
locals: {},
|
42
44
|
title: nil,
|
43
45
|
head: nil,
|
44
46
|
layout: 'layout.haml',
|
@@ -47,9 +49,9 @@ module LeanWeb
|
|
47
49
|
&block
|
48
50
|
)
|
49
51
|
@content_for[:title] = title unless title.nil?
|
50
|
-
content = render_by_extension(path, sub_layout, options, &block)
|
52
|
+
content = render_by_extension(path, locals, sub_layout, options, &block)
|
51
53
|
prepare_head(**head) unless head.nil?
|
52
|
-
render_response(layout, 'text/html'){ content }
|
54
|
+
render_response(layout, locals, 'text/html'){ content }
|
53
55
|
end
|
54
56
|
|
55
57
|
# Render response for missing static action methods. Called from
|
@@ -65,7 +67,7 @@ module LeanWeb
|
|
65
67
|
# @param options [Hash] Check `Tilt::EmacsOrg` options.
|
66
68
|
# @option options [String] :setupfile can be absolute or relative to
|
67
69
|
# {VIEW_PATH}.
|
68
|
-
def render_org(path, layout: nil, options: {})
|
70
|
+
def render_org(path, locals, layout: nil, options: {})
|
69
71
|
options[:setupfile] = absolute_view_path(options[:setupfile]) \
|
70
72
|
if options.include?(:setupfile)
|
71
73
|
|
@@ -75,10 +77,10 @@ module LeanWeb
|
|
75
77
|
unless @content_for.include?(:title)
|
76
78
|
|
77
79
|
if layout
|
78
|
-
create_template(layout)
|
79
|
-
|
80
|
-
org_template.render(self)
|
80
|
+
return create_template(layout)
|
81
|
+
.render(self, locals) { org_template.render(self, locals) }
|
81
82
|
end
|
83
|
+
org_template.render(self, locals)
|
82
84
|
end
|
83
85
|
|
84
86
|
# @param path [String]
|
@@ -86,7 +88,7 @@ module LeanWeb
|
|
86
88
|
# @param options [Hash] Check `RedCarpet` `render_options`.
|
87
89
|
# @option options [true] :toc To place an HTML based table of contents on
|
88
90
|
# `@content_for[:toc]` and render with option `:with_toc_data`.
|
89
|
-
def render_markdown(path, layout: nil, options: {})
|
91
|
+
def render_markdown(path, locals, layout: nil, options: {})
|
90
92
|
maybe_render_markdown_toc!(path, options)
|
91
93
|
markdown_template = create_template(path, options)
|
92
94
|
|
@@ -94,10 +96,10 @@ module LeanWeb
|
|
94
96
|
unless @content_for.include?(:title)
|
95
97
|
|
96
98
|
if layout
|
97
|
-
create_template(layout)
|
98
|
-
|
99
|
-
markdown_template.render(self)
|
99
|
+
return create_template(layout)
|
100
|
+
.render(self, locals) { markdown_template.render(self, locals) }
|
100
101
|
end
|
102
|
+
markdown_template.render(self, locals)
|
101
103
|
end
|
102
104
|
|
103
105
|
# If `options[:toc]` is set, deletes options `:toc` and adds
|
@@ -132,36 +134,37 @@ module LeanWeb
|
|
132
134
|
end
|
133
135
|
|
134
136
|
# @param path [String]
|
137
|
+
# @param locals [Hash]
|
135
138
|
# @param layout [String]
|
136
139
|
# @param options [Hash] Check `Haml` options.
|
137
140
|
# @yield If block given.
|
138
|
-
def render_other(path, layout: nil, options: {})
|
141
|
+
def render_other(path, locals, layout: nil, options: {})
|
139
142
|
template = create_template(path, options)
|
140
143
|
if layout
|
141
|
-
create_template(layout).render(self) do
|
142
|
-
template.render(self){ yield if block_given? }
|
144
|
+
create_template(layout).render(self, locals) do
|
145
|
+
template.render(self, locals){ yield if block_given? }
|
143
146
|
end
|
144
147
|
else
|
145
|
-
template.render(self){ yield if block_given? }
|
148
|
+
template.render(self, locals){ yield if block_given? }
|
146
149
|
end
|
147
150
|
end
|
148
151
|
|
149
152
|
# rubocop:disable Metrics/MethodLength
|
150
|
-
def render_by_extension(path, layout, options, &block)
|
153
|
+
def render_by_extension(path, locals, layout, options, &block)
|
151
154
|
ext = File.extname(path)[1..]
|
152
155
|
options = options || template_defaults[ext] || {}
|
153
156
|
|
154
157
|
case ext
|
155
158
|
when 'org'
|
156
|
-
return render_org(path, layout: layout, options: options)
|
159
|
+
return render_org(path, locals, layout: layout, options: options)
|
157
160
|
when 'md'
|
158
|
-
return render_markdown(path, layout: layout, options: options)
|
161
|
+
return render_markdown(path, locals, layout: layout, options: options)
|
159
162
|
when 'haml'
|
160
163
|
@content_for[:title] = find_title('haml', path) \
|
161
164
|
unless @content_for.include?(:title)
|
162
165
|
end
|
163
166
|
|
164
|
-
render_other(path, layout: layout, options: options, &block)
|
167
|
+
render_other(path, locals, layout: layout, options: options, &block)
|
165
168
|
end
|
166
169
|
# rubocop:enable Metrics/MethodLength
|
167
170
|
|
@@ -3,14 +3,15 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
require 'date'
|
11
11
|
require 'fileutils'
|
12
12
|
require 'json'
|
13
13
|
require 'rack/session/abstract/id'
|
14
|
+
require 'tmpdir'
|
14
15
|
|
15
16
|
module Rack
|
16
17
|
module Session
|
data/lib/leanweb/app.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
require 'rack'
|
11
11
|
|
data/lib/leanweb/controller.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
require 'rack'
|
11
11
|
require 'tilt'
|
@@ -32,17 +32,21 @@ module LeanWeb
|
|
32
32
|
#
|
33
33
|
# @param path [String] Might be an absolute path or a relative path to
|
34
34
|
# `src/views/`.
|
35
|
+
# @param locals [Hash] Local variables for rendered document.
|
35
36
|
# @param content_type [String] Defaults to the proper Content-Type for file
|
36
37
|
# extension, `text/plain` on unknown files.
|
37
38
|
# @yield Optionally pass a block for nested rendering.
|
38
39
|
# @return [Rack::Request#finish] A valid Rack response.
|
39
|
-
def render_response(path, content_type = nil, &block)
|
40
|
+
def render_response(path, locals = {}, content_type = nil, &block)
|
40
41
|
template = create_template(path)
|
41
42
|
@response.set_header(
|
42
43
|
'Content-Type',
|
43
|
-
content_type || template.class.metadata[:mime_type] ||
|
44
|
+
content_type || template.class.metadata[:mime_type] ||
|
45
|
+
template.class.superclass.metadata[:mime_type] || 'text/plain'
|
46
|
+
)
|
47
|
+
@response.write(
|
48
|
+
template.render(self, locals){ block.call if block_given? }
|
44
49
|
)
|
45
|
-
@response.write(template.render(self){ block.call if block_given? })
|
46
50
|
@response.finish
|
47
51
|
end
|
48
52
|
|
data/lib/leanweb/helpers.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
|
11
11
|
module LeanWeb
|
data/lib/leanweb/route.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
require 'rack/mock'
|
11
11
|
|
data/lib/leanweb/version.rb
CHANGED
data/lib/leanweb.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
|
4
4
|
#
|
5
5
|
# This file is part of "LeanWeb" and licensed under the terms of the GNU Affero
|
6
|
-
# General Public License version 3 with permissions
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# General Public License version 3 with additional permissions.
|
7
|
+
# You should have received a copy of this license along with the software. If
|
8
|
+
# not, see <https://gnu.org/licenses/>.
|
9
9
|
|
10
10
|
# LeanWeb is a minimal hybrid static / dynamic web framework.
|
11
11
|
module LeanWeb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leanweb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Freeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|