leanweb 0.4.2 → 0.5.0

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: c06365a703af2701788ef2a910f9bf93235ec58f9ae553f5cc8680c3a69b24d1
4
- data.tar.gz: 538381c1f9b7fd0fc4fe34151236319cb61148e522ec76eebd1c3ae9bb6adef5
3
+ metadata.gz: 6ffe16c4e32b210678118c5ef8a55293d3a67e0d1e8ada3014b9913dd17b2abb
4
+ data.tar.gz: 7e7da7e24539d389e688e2a0d3f88b5dca3c19804a104bc4ea2fe5f7fd7beb10
5
5
  SHA512:
6
- metadata.gz: 9d14b40f59e531bd51ee83a553f157663eae6be88b1808d91d659835fef6184488855ec7895b7da6239c8b180e68e3e2bdd60740beece777142234747b5cb54f
7
- data.tar.gz: 8562fc17fc25bfbb72ea0b1aa01a6432de76de48e9d5f6b0f13391410017d601eac91b58086ba3b782ecbff9f0a4d4adf6e9de716b558c0da1ecd598cac93f29
6
+ metadata.gz: cd9730e0fd3f231d0dfa9d7cafcad4ece3d3e46f7665f77bf497e8a9f9789a5ef030c70fd42ec19606820a1fd2934005b1f09a7750e37a3766e278d7363beb0f
7
+ data.tar.gz: 389915c7ec7301ecfc7cab2e2758e4e4de5f689ffaf3f77cb8d8de35159170db5658a0639112b476d3e8035f8628f24bbf19b3c2fac89a783813dedcebcf9b8d
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 for compatibility with the
8
- # Hacktivista General Public License. You should have received a copy of this
9
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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 'rake'
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
- use(Rack::Static, urls: [''], root: 'public', cascade: true)
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 LeanWeb::App.new(ROUTES)
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(['public/assets', 'src/controllers', 'src/views'])
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.")
@@ -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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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'
@@ -30,7 +30,7 @@ class Hawese
30
30
 
31
31
  def payment_methods(country = '*', currency = nil)
32
32
  endpoint = String.new(
33
- "#{ENDPOINT}/gateways/payment-methods/purchase?country=#{country}"
33
+ "#{ENDPOINT}/#{ORIGIN}/gateways/payment-methods/purchase?country=#{country}"
34
34
  )
35
35
  endpoint << "&currency=#{currency}" if currency
36
36
  uri = URI(endpoint)
@@ -38,14 +38,13 @@ class Hawese
38
38
  end
39
39
 
40
40
  def gateway_schema(gateway, query_params, schema = 'purchase')
41
- uri = URI("#{ENDPOINT}/gateways/#{gateway}/schemas/#{schema}")
41
+ uri = URI("#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}/schemas/#{schema}")
42
42
  uri.query = URI.encode_www_form(query_params)
43
43
  JSON.parse(Net::HTTP.get(uri), symbolize_names: true)
44
44
  end
45
45
 
46
46
  def purchase(gateway, fields)
47
- fields[:origin] = ORIGIN
48
- uri = URI("#{ENDPOINT}/gateways/#{gateway}/purchase")
47
+ uri = URI("#{ENDPOINT}/#{ORIGIN}/gateways/#{gateway}/purchase")
49
48
  uri.query = URI.encode_www_form(return_url: RETURN_URL)
50
49
  response = Net::HTTP.post(
51
50
  uri,
@@ -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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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: #{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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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).render(self){ org_template.render(self) }
79
- else
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).render(self){ markdown_template.render(self) }
98
- else
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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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
 
@@ -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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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] || 'text/plain'
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
 
@@ -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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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
 
@@ -9,5 +9,5 @@
9
9
 
10
10
 
11
11
  module LeanWeb
12
- VERSION = '0.4.2'
12
+ VERSION = '0.5.0'
13
13
  end
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 for compatibility with the
7
- # Hacktivista General Public License. You should have received a copy of this
8
- # license along with the software. If not, see <https://gnu.org/licenses/>.
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.2
4
+ version: 0.5.0
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-04-09 00:00:00.000000000 Z
11
+ date: 2023-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack