phlex 1.10.3 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/phlex/svg.rb CHANGED
@@ -1,20 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Phlex
4
- class SVG < SGML
5
- autoload :StandardElements, "phlex/svg/standard_elements"
3
+ class Phlex::SVG < Phlex::SGML
4
+ autoload :StandardElements, "phlex/svg/standard_elements"
6
5
 
7
- include StandardElements
6
+ include StandardElements
8
7
 
9
- # This should be extended after all method definitions
10
- extend ElementClobberingGuard
8
+ # This should be extended after all method definitions
9
+ extend Phlex::ElementClobberingGuard
11
10
 
12
- def content_type
13
- "image/svg+xml"
14
- end
11
+ def content_type
12
+ "image/svg+xml"
13
+ end
15
14
 
16
- def filename
17
- nil
18
- end
15
+ def filename
16
+ nil
19
17
  end
20
18
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "capybara"
4
+
5
+ module Phlex::Testing::Capybara
6
+ include Phlex::Testing::SGML
7
+
8
+ def self.included(mod)
9
+ if defined?(Minitest::Test) && Minitest::Test > mod
10
+ require "capybara/minitest"
11
+ mod.include Capybara::Minitest::Assertions
12
+ end
13
+
14
+ if defined?(RSpec::Core::ExampleGroup) && RSpec::Core::ExampleGroup > mod
15
+ require "capybara/rspec"
16
+ mod.include Capybara::RSpecMatchers
17
+ end
18
+ end
19
+
20
+ attr_reader :page
21
+ alias_method :component, :page
22
+
23
+ def render(...)
24
+ @page = ::Capybara::Node::Simple.new(
25
+ render_to_string(...),
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokogiri"
4
+
5
+ module Phlex::Testing::Nokogiri
6
+ include Phlex::Testing::SGML
7
+
8
+ def render_fragment(...)
9
+ ::Nokogiri::HTML5.fragment(
10
+ render_to_string(...),
11
+ )
12
+ end
13
+
14
+ def render_document(...)
15
+ ::Nokogiri::HTML5(
16
+ render_to_string(...),
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "nokolexbor"
4
+
5
+ module Phlex::Testing::Nokolexbor
6
+ include Phlex::Testing::SGML
7
+
8
+ def render_fragment(...)
9
+ Nokolexbor::DocumentFragment.parse(
10
+ render_to_string(...),
11
+ )
12
+ end
13
+
14
+ def render_document(...)
15
+ ::Nokolexbor::HTML(
16
+ render_to_string(...),
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phlex::Testing::SGML
4
+ def render_to_string(component, &)
5
+ component.call(view_context:, &)
6
+ end
7
+
8
+ def view_context = nil
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "phlex"
4
+
5
+ module Phlex::Testing
6
+ autoload :SGML, "phlex/testing/sgml"
7
+ autoload :Capybara, "phlex/testing/capybara"
8
+ autoload :Nokogiri, "phlex/testing/nokogiri"
9
+ autoload :Nokolexbor, "phlex/testing/nokolexbor"
10
+ end
data/lib/phlex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex
4
- VERSION = "1.10.3"
4
+ VERSION = "2.0.0.beta1"
5
5
  end
data/lib/phlex.rb CHANGED
@@ -1,54 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "erb"
4
+ require "set"
4
5
 
5
6
  module Phlex
7
+ autoload :ArgumentError, "phlex/errors/argument_error"
8
+ autoload :DoubleRenderError, "phlex/errors/double_render_error"
9
+ autoload :BlackHole, "phlex/black_hole"
10
+ autoload :CSV, "phlex/csv"
11
+ autoload :Callable, "phlex/callable"
6
12
  autoload :Context, "phlex/context"
7
13
  autoload :DeferredRender, "phlex/deferred_render"
8
14
  autoload :ElementClobberingGuard, "phlex/element_clobbering_guard"
9
15
  autoload :Elements, "phlex/elements"
16
+ autoload :Error, "phlex/error"
17
+ autoload :FIFO, "phlex/fifo"
10
18
  autoload :HTML, "phlex/html"
11
19
  autoload :Helpers, "phlex/helpers"
20
+ autoload :Kit, "phlex/kit"
21
+ autoload :NameError, "phlex/errors/name_error"
12
22
  autoload :SGML, "phlex/sgml"
13
23
  autoload :SVG, "phlex/svg"
14
- autoload :Unbuffered, "phlex/unbuffered"
15
- autoload :ConcurrentMap, "phlex/concurrent_map"
16
- autoload :BlackHole, "phlex/black_hole"
17
- autoload :CSV, "phlex/csv"
18
- autoload :Callable, "phlex/callable"
19
- autoload :Kit, "phlex/kit"
20
24
 
21
- # Included in all Phlex exceptions allowing you to match any Phlex error.
22
- # @example Rescue any Phlex error:
23
- # rescue Phlex::Error
24
- module Error; end
25
+ Escape = ERB::Escape
26
+ ATTRIBUTE_CACHE = FIFO.new
27
+ SUPPORTS_FIBER_STORAGE = RUBY_ENGINE == "ruby"
28
+ Null = Object.new.freeze
25
29
 
26
- if defined?(ERB::Escape)
27
- Escape = ERB::Escape
28
- else
29
- Escape = ERB::Util
30
- end
31
-
32
- # A specialised ArgumentError for Phlex.
33
- class ArgumentError < ::ArgumentError
34
- include Error
35
- end
36
-
37
- # A specialised NameError for Phlex.
38
- class NameError < ::NameError
39
- include Error
40
- end
41
-
42
- # @api private
43
- ATTRIBUTE_CACHE = {}
44
-
45
- SUPPORTS_FIBER_STORAGE = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2")
46
- end
30
+ CACHED_FILES = Set.new
47
31
 
48
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
49
- class Symbol
50
- def name
51
- to_s
32
+ def self.__expand_attribute_cache__(file_path)
33
+ unless CACHED_FILES.include?(file_path)
34
+ CACHED_FILES << file_path
35
+ Phlex::ATTRIBUTE_CACHE.expand(File.size(file_path))
52
36
  end
53
37
  end
54
38
  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: 1.10.3
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-01 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A high-performance view framework optimised for fun.
14
14
  email:
@@ -21,22 +21,31 @@ files:
21
21
  - README.md
22
22
  - lib/phlex.rb
23
23
  - lib/phlex/black_hole.rb
24
- - lib/phlex/callable.rb
25
24
  - lib/phlex/context.rb
26
25
  - lib/phlex/csv.rb
27
26
  - lib/phlex/deferred_render.rb
28
27
  - lib/phlex/element_clobbering_guard.rb
29
28
  - lib/phlex/elements.rb
29
+ - lib/phlex/error.rb
30
+ - lib/phlex/errors/argument_error.rb
31
+ - lib/phlex/errors/double_render_error.rb
32
+ - lib/phlex/errors/name_error.rb
33
+ - lib/phlex/fifo.rb
30
34
  - lib/phlex/helpers.rb
31
35
  - lib/phlex/html.rb
32
36
  - lib/phlex/html/standard_elements.rb
33
37
  - lib/phlex/html/void_elements.rb
34
38
  - lib/phlex/kit.rb
35
39
  - lib/phlex/sgml.rb
40
+ - lib/phlex/sgml/safe_object.rb
41
+ - lib/phlex/sgml/safe_value.rb
36
42
  - lib/phlex/svg.rb
37
43
  - lib/phlex/svg/standard_elements.rb
38
- - lib/phlex/testing/view_helper.rb
39
- - lib/phlex/unbuffered.rb
44
+ - lib/phlex/testing.rb
45
+ - lib/phlex/testing/capybara.rb
46
+ - lib/phlex/testing/nokogiri.rb
47
+ - lib/phlex/testing/nokolexbor.rb
48
+ - lib/phlex/testing/sgml.rb
40
49
  - lib/phlex/version.rb
41
50
  homepage: https://www.phlex.fun
42
51
  licenses:
@@ -55,14 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
64
  requirements:
56
65
  - - ">="
57
66
  - !ruby/object:Gem::Version
58
- version: '2.7'
67
+ version: 3.3.1
59
68
  required_rubygems_version: !ruby/object:Gem::Requirement
60
69
  requirements:
61
70
  - - ">="
62
71
  - !ruby/object:Gem::Version
63
72
  version: '0'
64
73
  requirements: []
65
- rubygems_version: 3.5.3
74
+ rubygems_version: 3.5.18
66
75
  signing_key:
67
76
  specification_version: 4
68
77
  summary: A fun framework for building views in Ruby.
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- module Phlex::Callable
5
- def to_proc
6
- method(:call).to_proc
7
- end
8
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Phlex::Testing
4
- module ViewHelper
5
- def render(view, &block)
6
- if view.is_a?(Class) && view < Phlex::SGML
7
- view = view.new
8
- end
9
-
10
- view.call(view_context: view_context, &block)
11
- end
12
-
13
- def view_context
14
- nil
15
- end
16
- end
17
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- class Phlex::Unbuffered < BasicObject
5
- def initialize(object)
6
- @object = object
7
- end
8
-
9
- def inspect
10
- "Unbuffered(#{@object.class.name})[object: #{@object.inspect}]"
11
- end
12
-
13
- # Borrow some important methods from Object
14
- define_method :__class__,
15
- ::Object.instance_method(:class)
16
-
17
- define_method :__public_send__,
18
- ::Object.instance_method(:public_send)
19
-
20
- def respond_to_missing?(...)
21
- @object.respond_to?(...)
22
- end
23
-
24
- def method_missing(name, *args, **kwargs, &block)
25
- if @object.respond_to?(name)
26
-
27
- __class__.define_method(name) do |*a, **k, &b|
28
- @object.capture { @object.public_send(name, *a, **k, &b) }
29
- end
30
-
31
- # Now we've defined this missing method, we can call it.
32
- __public_send__(name, *args, **kwargs, &block)
33
- else
34
- super
35
- end
36
- end
37
-
38
- # Forward some methods to the original underlying method
39
- def call(...)
40
- @object.call(...)
41
- end
42
-
43
- def send(...)
44
- @object.send(...)
45
- end
46
-
47
- def public_send(...)
48
- @object.public_send(...)
49
- end
50
- end