phlex 2.1.0 → 2.1.1

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: b8db189359fc8003771075a598fbeed0c2205ca52604fd829d77afe3c0b3a467
4
- data.tar.gz: e5446344e9a83c982fdfa94d4d31abd4b7511858704cc2e9f9d285ad9740b9c3
3
+ metadata.gz: e0de463dbf4f663fc2ac8dd8d0b0a080dc8d7bf90ba209d56b366b36634e9cc9
4
+ data.tar.gz: ccad039d4962eb42076c562cb9f9617197f878a1860b13f66aae2b34f2686333
5
5
  SHA512:
6
- metadata.gz: db1c7e4b591440cea077fb99285552f443301564b293f2a0cf0098750d514af3ac48684d820398ac588570ba71f6f1c1284b72c3b32d6f54f48d20c457a476eb
7
- data.tar.gz: fb9ff7728339e8edbcae2b9031c41f77ae2d28e68963b8c27368575d44a20935ff6393730d180579bb29d9a3786e43c1c6388223d0115b17c6d35b31245b64ff
6
+ metadata.gz: 959b8c7b1bdbbf281b0da7576257719da2ba077045e9ad1d673348d60a01dfa731b6b9b2e9031cce81e896f98a195478008d667e99bf471e50348bc6b978c393
7
+ data.tar.gz: 93dab7d61efa8f2009698cb8ae7d12748b4cb1bfe5c2bf48e58c41e5c930f923789c00ff3c346e878107f9cbe280951e23f35fe5482c453799f5c7e81293715e
data/lib/phlex/sgml.rb CHANGED
@@ -5,6 +5,17 @@ class Phlex::SGML
5
5
  UNSAFE_ATTRIBUTES = Set.new(%w[srcdoc sandbox http-equiv]).freeze
6
6
  REF_ATTRIBUTES = Set.new(%w[href src action formaction lowsrc dynsrc background ping]).freeze
7
7
 
8
+ ERBCompiler = ERB::Compiler.new("<>").tap do |compiler|
9
+ compiler.pre_cmd = [""]
10
+ compiler.put_cmd = "@_state.buffer.<<"
11
+ compiler.insert_cmd = "__implicit_output__"
12
+ compiler.post_cmd = ["nil"]
13
+
14
+ def compiler.add_insert_cmd(out, content)
15
+ out.push("#{@insert_cmd}((#{content}))")
16
+ end
17
+ end
18
+
8
19
  autoload :Elements, "phlex/sgml/elements"
9
20
  autoload :SafeObject, "phlex/sgml/safe_object"
10
21
  autoload :SafeValue, "phlex/sgml/safe_value"
@@ -29,6 +40,40 @@ class Phlex::SGML
29
40
  super
30
41
  end
31
42
  end
43
+
44
+ def erb(method_name, erb = nil, locals: nil, &block)
45
+ loc = caller_locations(1, 1)[0]
46
+ path = loc.path.delete_suffix(".rb")
47
+ file = loc.path
48
+ line = loc.lineno - 1
49
+
50
+ unless erb
51
+ method_path = "#{path}/#{method_name}.html.erb"
52
+ sidecar_path = "#{path}.html.erb"
53
+
54
+ if File.exist?(method_path)
55
+ erb = File.read(method_path)
56
+ file = method_path
57
+ line = 1
58
+ elsif method_name == :view_template && File.exist?(sidecar_path)
59
+ erb = File.read(sidecar_path)
60
+ file = sidecar_path
61
+ line = 1
62
+ else
63
+ raise Phlex::RuntimeError.new(<<~MESSAGE)
64
+ No ERB template found for #{method_name}
65
+ MESSAGE
66
+ end
67
+ end
68
+
69
+ code, _enc = ERBCompiler.compile(erb)
70
+
71
+ class_eval(<<~RUBY, file, line)
72
+ def #{method_name} #{locals}
73
+ #{code}
74
+ end
75
+ RUBY
76
+ end
32
77
  end
33
78
 
34
79
  def view_template
data/lib/phlex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex
4
- VERSION = "2.1.0"
4
+ VERSION = "2.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  - Will Cosgrove
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-05 00:00:00.000000000 Z
11
+ date: 2025-03-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Build HTML, SVG and CSV views with Ruby classes.
14
14
  email: