phlex-rails 0.6.1 → 0.7.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 +4 -4
- data/lib/generators/phlex/component/USAGE +8 -0
- data/lib/generators/phlex/component/component_generator.rb +12 -0
- data/lib/generators/phlex/component/templates/component.rb.erb +9 -0
- data/lib/generators/phlex/controller/USAGE +2 -2
- data/lib/generators/phlex/controller/controller_generator.rb +56 -54
- data/lib/generators/phlex/controller/templates/controller.rb.erb +5 -1
- data/lib/generators/phlex/controller/templates/view.rb.erb +7 -10
- data/lib/generators/phlex/install/USAGE +8 -0
- data/lib/generators/phlex/install/install_generator.rb +61 -0
- data/lib/generators/phlex/install/templates/application_component.rb +12 -0
- data/lib/generators/phlex/install/templates/application_layout.rb +24 -0
- data/lib/generators/phlex/install/templates/application_view.rb +9 -0
- data/lib/generators/phlex/view/USAGE +2 -3
- data/lib/generators/phlex/view/templates/view.rb.erb +7 -12
- data/lib/generators/phlex/view/view_generator.rb +6 -17
- data/lib/phlex/rails/helpers/routes.rb +2 -0
- data/lib/phlex/rails/helpers/tag.rb +4 -0
- data/lib/phlex/rails/helpers/turbo_stream.rb +14 -0
- data/lib/phlex/rails/helpers.rb +7 -7
- data/lib/phlex/rails/html/format.rb +7 -0
- data/lib/phlex/rails/layout.rb +45 -0
- data/lib/phlex/rails/{html → sgml}/append_method_added_warning.rb +2 -2
- data/lib/phlex/rails/{html → sgml}/class_methods.rb +1 -1
- data/lib/phlex/rails/{html → sgml}/overrides.rb +17 -16
- data/lib/phlex/rails/version.rb +1 -1
- data/lib/phlex/rails.rb +21 -9
- metadata +21 -25
- data/lib/generators/phlex/layout/USAGE +0 -8
- data/lib/generators/phlex/layout/layout_generator.rb +0 -13
- data/lib/generators/phlex/layout/templates/layout.rb.erb +0 -30
- data/lib/generators/phlex/page/USAGE +0 -8
- data/lib/generators/phlex/page/page_generator.rb +0 -13
- data/lib/generators/phlex/page/templates/page.rb.erb +0 -11
- data/lib/install/phlex.rb +0 -26
- data/lib/tasks/phlex_tasks.rake +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90e5d36afb3e649892cc3e9c72fb4f5f9e7b6638ae50c95a0791ede0afe4355b
|
4
|
+
data.tar.gz: 22ae3aecb60afc9e72be8bc5e7b13736e9901ccb0ada86d5a2dbfa5a69319166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 833b460794df4a260a766ebbf226b62d8b482e6c62a0c847499c9f59ce2a6b620e626885a8bd0ace726046ee095d32d95673c0fa5ad2a62d0c929520c6989710
|
7
|
+
data.tar.gz: 995bce4e399888efb0c35fd3f6a0d5c8c6fab5a7b230b613b4c61e71946c4380643dae8273e1ad4cab86a61c04f7a1d43b7229b86c4c0817e42b84a7db8f06fe
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Generators
|
4
|
+
class ComponentGenerator < ::Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
def create_view
|
8
|
+
@path = File.join("app/views/components", class_path, "#{file_name}_component.rb")
|
9
|
+
template "component.rb.erb", @path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,72 +1,74 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Phlex
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
3
|
+
module Phlex::Generators
|
4
|
+
class ControllerGenerator < ::Rails::Generators::NamedBase # :nodoc:
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
check_class_collision suffix: "Controller"
|
8
|
+
|
9
|
+
argument :actions,
|
10
|
+
type: :array,
|
11
|
+
default: [],
|
12
|
+
banner: "action action"
|
13
|
+
|
14
|
+
class_option :skip_routes,
|
15
|
+
type: :boolean,
|
16
|
+
desc: "Don't add routes to config/routes.rb."
|
17
|
+
|
18
|
+
class_option :parent,
|
19
|
+
type: :string,
|
20
|
+
default: "ApplicationController",
|
21
|
+
desc: "The parent class for the generated controller"
|
22
|
+
|
23
|
+
def create_controllers
|
24
|
+
template "controller.rb.erb", File.join(
|
25
|
+
"app/controllers", class_path, "#{file_name}_controller.rb"
|
26
|
+
)
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def copy_views
|
30
|
+
actions.each do |action|
|
31
|
+
@action = action
|
32
|
+
@path = File.join(
|
33
|
+
"app/views", class_path, file_name, "#{action}_view.rb"
|
34
|
+
)
|
31
35
|
|
32
|
-
|
33
|
-
::Rails::Generators.invoke("phlex:page", [name + "/" + action])
|
34
|
-
end
|
36
|
+
template "view.rb.erb", @path
|
35
37
|
end
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
routing_code = "resources :#{file_name}"
|
40
|
+
def add_routes
|
41
|
+
return if options[:skip_routes]
|
41
42
|
|
42
|
-
|
43
|
-
routing_code << ", only: [#{actions.map { ":#{_1}" }.join(', ')}]"
|
44
|
-
end
|
43
|
+
routing_code = "resources :#{file_name}"
|
45
44
|
|
46
|
-
|
45
|
+
if actions.any?
|
46
|
+
routing_code << ", only: [#{actions.map { ":#{_1}" }.join(', ')}]"
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
49
|
+
route routing_code, namespace: regular_class_path
|
50
|
+
end
|
52
51
|
|
53
|
-
|
52
|
+
hook_for :test_framework, as: :controller do |generator|
|
53
|
+
invoke generator, [remove_possible_suffix(name), actions]
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
options[:parent]
|
57
|
-
end
|
56
|
+
private
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def parent_class_name
|
59
|
+
options[:parent]
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def file_name
|
63
|
+
remove_possible_suffix(super)
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
def name
|
67
|
+
remove_possible_suffix(super)
|
68
|
+
end
|
69
|
+
|
70
|
+
def remove_possible_suffix(name)
|
71
|
+
name.sub(/_?controller$/i, "")
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
@@ -1,8 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
<% module_namespacing do -%>
|
2
4
|
class <%= class_name %>Controller < <%= parent_class_name.classify %>
|
5
|
+
layout -> { ApplicationLayout }
|
6
|
+
|
3
7
|
<% actions.each do |action| -%>
|
4
8
|
def <%= action %>
|
5
|
-
render
|
9
|
+
render <%= class_name %>::<%= action.camelize %>View.new
|
6
10
|
end
|
7
11
|
<%= "\n" unless action == actions.last -%>
|
8
12
|
<% end -%>
|
@@ -1,12 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
<% module_namespacing do -%>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
h1 { "<%= class_name %>#<%= @action %>" }
|
7
|
-
p { "Find me in <%= @path %>" }
|
8
|
-
<%= "# " unless @has_layout %>end
|
9
|
-
end
|
4
|
+
class <%= class_name %>::<%= @action.classify %>View < ApplicationView
|
5
|
+
def template
|
6
|
+
h1 { "<%= class_name %> <%= @action %>" }
|
7
|
+
p { "Find me in <%= @path %>" }
|
10
8
|
end
|
11
|
-
end
|
12
|
-
<% end %>
|
9
|
+
end<% end %>
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Generators
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
6
|
+
|
7
|
+
APPLICATION_CONFIGURATION_PATH = Rails.root.join("config/application.rb")
|
8
|
+
TAILWIND_CONFIGURATION_PATH = Rails.root.join("config/tailwind.config.js")
|
9
|
+
|
10
|
+
def autoload_components
|
11
|
+
return unless APPLICATION_CONFIGURATION_PATH.exist?
|
12
|
+
|
13
|
+
inject_into_class(
|
14
|
+
APPLICATION_CONFIGURATION_PATH,
|
15
|
+
"Application",
|
16
|
+
%( config.autoload_paths << "\#{root}/app/views/components"\n)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def autoload_layouts
|
21
|
+
return unless APPLICATION_CONFIGURATION_PATH.exist?
|
22
|
+
|
23
|
+
inject_into_class(
|
24
|
+
APPLICATION_CONFIGURATION_PATH,
|
25
|
+
"Application",
|
26
|
+
%( config.autoload_paths << "\#{root}/app/views/layouts"\n)
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def autoload_views
|
31
|
+
return unless APPLICATION_CONFIGURATION_PATH.exist?
|
32
|
+
|
33
|
+
inject_into_class(
|
34
|
+
APPLICATION_CONFIGURATION_PATH,
|
35
|
+
"Application",
|
36
|
+
%( config.autoload_paths << "\#{root}/app/views"\n)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure_tailwind
|
41
|
+
return unless TAILWIND_CONFIGURATION_PATH.exist?
|
42
|
+
|
43
|
+
insert_into_file TAILWIND_CONFIGURATION_PATH, after: "content: [" do
|
44
|
+
"\n './app/views/**/*.rb'," \
|
45
|
+
"\n './app/components/**/*rb',"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_application_component
|
50
|
+
template "application_component.rb", Rails.root.join("app/views/components/application_component.rb")
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_application_layout
|
54
|
+
template "application_layout.rb", Rails.root.join("app/views/layouts/application_layout.rb")
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_application_view
|
58
|
+
template "application_view.rb", Rails.root.join("app/views/application_view.rb")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ApplicationLayout < ApplicationView
|
4
|
+
include Phlex::Rails::Layout
|
5
|
+
|
6
|
+
def template(&block)
|
7
|
+
doctype
|
8
|
+
|
9
|
+
html do
|
10
|
+
head do
|
11
|
+
title { "You're awesome" }
|
12
|
+
meta name: "viewport", content: "width=device-width,initial-scale=1"
|
13
|
+
csp_meta_tag
|
14
|
+
csrf_meta_tags
|
15
|
+
stylesheet_link_tag "application", data_turbo_track: "reload"
|
16
|
+
javascript_importmap_tags
|
17
|
+
end
|
18
|
+
|
19
|
+
body do
|
20
|
+
main(&block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ApplicationView < ApplicationComponent
|
4
|
+
# The ApplicationView is an abstract class for all your views.
|
5
|
+
|
6
|
+
# By default, it inherits from `ApplicationComponent`, but you
|
7
|
+
# can change that to `Phlex::HTML` if you want to keep views and
|
8
|
+
# components independent.
|
9
|
+
end
|
@@ -2,8 +2,7 @@ Description:
|
|
2
2
|
Generates a Phlex view with the given name
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate phlex:view
|
5
|
+
rails generate phlex:view Articles::Index
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
app/views/
|
9
|
-
spec/views/sidebar_spec.rb or test/views/sidebar_test.rb
|
8
|
+
app/views/articles/index_view.rb
|
@@ -1,14 +1,9 @@
|
|
1
|
-
|
2
|
-
module Views
|
3
|
-
class <%= class_name %> < Phlex::HTML
|
4
|
-
include ApplicationView
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= class_name %>View < ApplicationView
|
5
|
+
def template
|
6
|
+
h1 { "<%= class_name %>" }
|
7
|
+
p { "Find me in <%= @path %>" }
|
12
8
|
end
|
13
|
-
end
|
14
|
-
<% end %>
|
9
|
+
end<% end %>
|
@@ -1,23 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Phlex
|
4
|
-
|
5
|
-
|
6
|
-
source_root File.expand_path("templates", __dir__)
|
3
|
+
module Phlex::Generators
|
4
|
+
class ViewGenerator < ::Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path("templates", __dir__)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
template "view.rb.erb", @path
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def layout
|
17
|
-
::Rails.root.join("app/views/layout.rb").exist?
|
18
|
-
end
|
19
|
-
|
20
|
-
# hook_for :test_framework
|
7
|
+
def create_view
|
8
|
+
@path = File.join("app/views", class_path, "#{file_name}_view.rb")
|
9
|
+
template "view.rb.erb", @path
|
21
10
|
end
|
22
11
|
end
|
23
12
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# An adapter for the <code>tag</code> helper.
|
4
|
+
# @note This helper is provided for completeness, but you should probably use Phlex tag methods directly instead.
|
3
5
|
module Phlex::Rails::Helpers::Tag
|
6
|
+
# Builds HTML tags
|
7
|
+
# @see https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag
|
4
8
|
def tag(...)
|
5
9
|
result = helpers.tag(...)
|
6
10
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# An adapter for the turbo-rails <code>turbo_stream</code> helper.
|
4
|
+
# @see https://github.com/hotwired/turbo-rails
|
5
|
+
module Phlex::Rails::Helpers::TurboStream
|
6
|
+
extend Phlex::Rails::HelperMacros
|
7
|
+
|
8
|
+
def turbo_stream(...)
|
9
|
+
Phlex::Rails::Buffered.new(
|
10
|
+
helpers.turbo_stream(...),
|
11
|
+
view: self
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
data/lib/phlex/rails/helpers.rb
CHANGED
@@ -1283,13 +1283,6 @@ module Phlex::Rails::Helpers
|
|
1283
1283
|
define_output_helper :turbo_include_tags
|
1284
1284
|
end
|
1285
1285
|
|
1286
|
-
module TurboStream
|
1287
|
-
extend Phlex::Rails::HelperMacros
|
1288
|
-
|
1289
|
-
# @!method turbo_stream(...)
|
1290
|
-
define_builder_yielding_helper :turbo_stream, Phlex::Rails::Buffered
|
1291
|
-
end
|
1292
|
-
|
1293
1286
|
module TurboStreamFrom
|
1294
1287
|
extend Phlex::Rails::HelperMacros
|
1295
1288
|
|
@@ -1313,6 +1306,13 @@ module Phlex::Rails::Helpers
|
|
1313
1306
|
define_output_helper :url_field_tag
|
1314
1307
|
end
|
1315
1308
|
|
1309
|
+
module URLOptions
|
1310
|
+
extend Phlex::Rails::HelperMacros
|
1311
|
+
|
1312
|
+
# @!method url_options(...)
|
1313
|
+
define_value_helper :url_options
|
1314
|
+
end
|
1315
|
+
|
1316
1316
|
module URLToAsset
|
1317
1317
|
extend Phlex::Rails::HelperMacros
|
1318
1318
|
|
data/lib/phlex/rails/layout.rb
CHANGED
@@ -12,5 +12,50 @@ module Phlex::Rails
|
|
12
12
|
include Helpers::JavaScriptIncludeTag
|
13
13
|
include Helpers::JavaScriptImportMapTags
|
14
14
|
include Helpers::JavaScriptImportModuleTag
|
15
|
+
|
16
|
+
module Interface
|
17
|
+
def render(view, _locals, &block)
|
18
|
+
component = new
|
19
|
+
|
20
|
+
component.call(view_context: view) do |yielded|
|
21
|
+
case yielded
|
22
|
+
when Symbol
|
23
|
+
output = view.view_flow.get(yielded)
|
24
|
+
else
|
25
|
+
output = yield
|
26
|
+
end
|
27
|
+
|
28
|
+
case output
|
29
|
+
when ActiveSupport::SafeBuffer
|
30
|
+
component.unsafe_raw output
|
31
|
+
end
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def identifier
|
38
|
+
name
|
39
|
+
end
|
40
|
+
|
41
|
+
def virtual_path
|
42
|
+
return @virtual_path if defined? @virtual_path
|
43
|
+
|
44
|
+
@virtual_path = name&.dup.tap do |n|
|
45
|
+
n.gsub!("::", ".")
|
46
|
+
n.gsub!(/([a-z])([A-Z])/, '\1_\2')
|
47
|
+
n.downcase!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.included(klass)
|
53
|
+
unless klass < Phlex::HTML
|
54
|
+
raise Phlex::ArgumentError,
|
55
|
+
"👋 #{name} should only be included into Phlex::HTML classes."
|
56
|
+
end
|
57
|
+
|
58
|
+
klass.extend(Interface)
|
59
|
+
end
|
15
60
|
end
|
16
61
|
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module Phlex
|
4
4
|
module Rails
|
5
|
-
module
|
5
|
+
module SGML
|
6
6
|
module AppendMethodAddedWarning
|
7
7
|
def method_added(name)
|
8
|
-
if name == :append || name == :safe_append
|
8
|
+
if name == :append || name == :safe_append= || name == :safe_concat
|
9
9
|
raise Phlex::NameError, "You shouldn't redefine the #{name} method as it's required for safe HTML output."
|
10
10
|
end
|
11
11
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Phlex
|
4
4
|
module Rails
|
5
|
-
module
|
5
|
+
module SGML
|
6
6
|
module Overrides
|
7
7
|
def helpers
|
8
8
|
if defined?(ViewComponent::Base) && @_view_context.is_a?(ViewComponent::Base)
|
@@ -12,11 +12,15 @@ module Phlex
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def render(renderable, *args, **kwargs, &block)
|
16
|
-
return super if renderable.is_a?(Phlex::
|
17
|
-
return super if renderable.is_a?(Class) && renderable < Phlex::
|
15
|
+
def render(renderable = nil, *args, **kwargs, &block)
|
16
|
+
return super if renderable.is_a?(Phlex::SGML)
|
17
|
+
return super if renderable.is_a?(Class) && renderable < Phlex::SGML
|
18
18
|
|
19
|
-
|
19
|
+
if renderable
|
20
|
+
@_target << @_view_context.render(renderable, *args, **kwargs, &block)
|
21
|
+
else
|
22
|
+
@_target << @_view_context.render(*args, **kwargs, &block)
|
23
|
+
end
|
20
24
|
|
21
25
|
nil
|
22
26
|
end
|
@@ -27,7 +31,7 @@ module Phlex
|
|
27
31
|
view_context.with_output_buffer(self) do
|
28
32
|
original_length = @_target.length
|
29
33
|
|
30
|
-
if args.length == 1 && Phlex::
|
34
|
+
if args.length == 1 && Phlex::SGML === args[0]
|
31
35
|
output = yield(
|
32
36
|
args[0].unbuffered
|
33
37
|
)
|
@@ -53,6 +57,7 @@ module Phlex
|
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
# @api private
|
56
61
|
def safe_append=(value)
|
57
62
|
return unless value
|
58
63
|
|
@@ -63,6 +68,10 @@ module Phlex
|
|
63
68
|
end
|
64
69
|
end
|
65
70
|
|
71
|
+
# @api private
|
72
|
+
alias_method :safe_concat, :safe_append=
|
73
|
+
|
74
|
+
# @api private
|
66
75
|
def append=(value)
|
67
76
|
case value
|
68
77
|
when ActiveSupport::SafeBuffer
|
@@ -88,30 +97,22 @@ module Phlex
|
|
88
97
|
return unless block
|
89
98
|
|
90
99
|
case block.binding.receiver
|
91
|
-
when Phlex::
|
100
|
+
when Phlex::SGML
|
92
101
|
super
|
93
102
|
else
|
94
103
|
@_view_context.with_output_buffer(self) { super }
|
95
104
|
end
|
96
|
-
|
97
|
-
# If it's a C-level Proc from Symbol#to_proc, it won't have a binding
|
98
|
-
rescue ::ArgumentError
|
99
|
-
super
|
100
105
|
end
|
101
106
|
|
102
107
|
private def yield_content_with_args(*args, &block)
|
103
108
|
return unless block
|
104
109
|
|
105
110
|
case block.binding.receiver
|
106
|
-
when Phlex::
|
111
|
+
when Phlex::SGML
|
107
112
|
super
|
108
113
|
else
|
109
114
|
@_view_context.with_output_buffer(self) { super }
|
110
115
|
end
|
111
|
-
|
112
|
-
# If it's a C-level Proc from Symbol#to_proc, it won't have a binding
|
113
|
-
rescue ::ArgumentError
|
114
|
-
super
|
115
116
|
end
|
116
117
|
end
|
117
118
|
end
|
data/lib/phlex/rails/version.rb
CHANGED
data/lib/phlex/rails.rb
CHANGED
@@ -3,16 +3,28 @@
|
|
3
3
|
require "phlex"
|
4
4
|
require "phlex/rails/engine"
|
5
5
|
|
6
|
-
module Phlex
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
module Phlex
|
7
|
+
module Rails
|
8
|
+
Loader = Zeitwerk::Loader.new.tap do |loader|
|
9
|
+
loader.push_dir("#{__dir__}/rails", namespace: Phlex::Rails)
|
10
|
+
loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
|
11
|
+
loader.inflector.inflect(
|
12
|
+
"html" => "HTML",
|
13
|
+
"sgml" => "SGML"
|
14
|
+
)
|
15
|
+
loader.setup
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
|
-
|
19
|
+
class SGML
|
20
|
+
extend Phlex::Rails::SGML::ClassMethods
|
21
|
+
extend Phlex::Rails::SGML::AppendMethodAddedWarning
|
15
22
|
|
16
|
-
|
17
|
-
|
23
|
+
prepend Phlex::Rails::SGML::Overrides
|
24
|
+
end
|
25
|
+
|
26
|
+
class HTML
|
27
|
+
extend Phlex::Rails::HTML::Format
|
28
|
+
include Phlex::Rails::HTML::Format
|
29
|
+
end
|
18
30
|
end
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phlex-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.3.1
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
19
|
+
version: '1.4'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.3.1
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
26
|
+
version: '1.4'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: rails
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,14 +50,14 @@ dependencies:
|
|
56
50
|
requirements:
|
57
51
|
- - "~>"
|
58
52
|
- !ruby/object:Gem::Version
|
59
|
-
version: '2'
|
53
|
+
version: '2.6'
|
60
54
|
type: :runtime
|
61
55
|
prerelease: false
|
62
56
|
version_requirements: !ruby/object:Gem::Requirement
|
63
57
|
requirements:
|
64
58
|
- - "~>"
|
65
59
|
- !ruby/object:Gem::Version
|
66
|
-
version: '2'
|
60
|
+
version: '2.6'
|
67
61
|
description: A high-performance view framework optimised for developer happiness.
|
68
62
|
email:
|
69
63
|
- joel@drapper.me
|
@@ -82,16 +76,18 @@ files:
|
|
82
76
|
- README.md
|
83
77
|
- SECURITY.md
|
84
78
|
- config.ru
|
79
|
+
- lib/generators/phlex/component/USAGE
|
80
|
+
- lib/generators/phlex/component/component_generator.rb
|
81
|
+
- lib/generators/phlex/component/templates/component.rb.erb
|
85
82
|
- lib/generators/phlex/controller/USAGE
|
86
83
|
- lib/generators/phlex/controller/controller_generator.rb
|
87
84
|
- lib/generators/phlex/controller/templates/controller.rb.erb
|
88
85
|
- lib/generators/phlex/controller/templates/view.rb.erb
|
89
|
-
- lib/generators/phlex/
|
90
|
-
- lib/generators/phlex/
|
91
|
-
- lib/generators/phlex/
|
92
|
-
- lib/generators/phlex/
|
93
|
-
- lib/generators/phlex/
|
94
|
-
- lib/generators/phlex/page/templates/page.rb.erb
|
86
|
+
- lib/generators/phlex/install/USAGE
|
87
|
+
- lib/generators/phlex/install/install_generator.rb
|
88
|
+
- lib/generators/phlex/install/templates/application_component.rb
|
89
|
+
- lib/generators/phlex/install/templates/application_layout.rb
|
90
|
+
- lib/generators/phlex/install/templates/application_view.rb
|
95
91
|
- lib/generators/phlex/view/USAGE
|
96
92
|
- lib/generators/phlex/view/templates/view.rb.erb
|
97
93
|
- lib/generators/phlex/view/view_generator.rb
|
@@ -99,7 +95,6 @@ files:
|
|
99
95
|
- lib/generators/rspec/view/view_generator.rb
|
100
96
|
- lib/generators/test_unit/templates/view_test.rb.erb
|
101
97
|
- lib/generators/test_unit/view_generator.rb
|
102
|
-
- lib/install/phlex.rb
|
103
98
|
- lib/phlex-rails.rb
|
104
99
|
- lib/phlex/rails.rb
|
105
100
|
- lib/phlex/rails/buffered.rb
|
@@ -113,13 +108,14 @@ files:
|
|
113
108
|
- lib/phlex/rails/helpers.rb
|
114
109
|
- lib/phlex/rails/helpers/routes.rb
|
115
110
|
- lib/phlex/rails/helpers/tag.rb
|
116
|
-
- lib/phlex/rails/
|
117
|
-
- lib/phlex/rails/html/
|
118
|
-
- lib/phlex/rails/html/overrides.rb
|
111
|
+
- lib/phlex/rails/helpers/turbo_stream.rb
|
112
|
+
- lib/phlex/rails/html/format.rb
|
119
113
|
- lib/phlex/rails/layout.rb
|
114
|
+
- lib/phlex/rails/sgml/append_method_added_warning.rb
|
115
|
+
- lib/phlex/rails/sgml/class_methods.rb
|
116
|
+
- lib/phlex/rails/sgml/overrides.rb
|
120
117
|
- lib/phlex/rails/version.rb
|
121
118
|
- lib/phlex/testing/rails/view_helper.rb
|
122
|
-
- lib/tasks/phlex_tasks.rake
|
123
119
|
- phlex_logo.png
|
124
120
|
homepage: https://www.phlex.fun
|
125
121
|
licenses:
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Phlex
|
4
|
-
module Generators
|
5
|
-
class LayoutGenerator < ::Rails::Generators::NamedBase
|
6
|
-
source_root File.expand_path("templates", __dir__)
|
7
|
-
|
8
|
-
def create_view
|
9
|
-
template "layout.rb.erb", File.join("app/views", class_path, "#{file_name}.rb")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
module Views
|
3
|
-
class <%= class_name %> < Phlex::HTML
|
4
|
-
include Phlex::Rails::Layout
|
5
|
-
|
6
|
-
def initialize(title:)
|
7
|
-
@title = title
|
8
|
-
end
|
9
|
-
|
10
|
-
def template(&)
|
11
|
-
doctype
|
12
|
-
|
13
|
-
html do
|
14
|
-
head do
|
15
|
-
meta charset: "utf-8"
|
16
|
-
csp_meta_tag
|
17
|
-
csrf_meta_tags
|
18
|
-
meta name: "viewport", content: "width=device-width,initial-scale=1"
|
19
|
-
title { @title }
|
20
|
-
stylesheet_link_tag "application"
|
21
|
-
end
|
22
|
-
|
23
|
-
body do
|
24
|
-
main(&)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
<% end %>
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Phlex
|
4
|
-
module Generators
|
5
|
-
class PageGenerator < ::Rails::Generators::NamedBase
|
6
|
-
source_root File.expand_path("templates", __dir__)
|
7
|
-
|
8
|
-
def create_view
|
9
|
-
template "page.rb.erb", File.join("app/views", class_path, "#{file_name}.rb")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/install/phlex.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
say "Installing Phlex..."
|
4
|
-
|
5
|
-
application_configuration_path = Rails.root.join("config/application.rb")
|
6
|
-
application_configuration_content = File.read(application_configuration_path)
|
7
|
-
|
8
|
-
pattern = %r(config.autoload_paths << (Rails.root.join\(.app.\)|.\#{root}/app.)\n)
|
9
|
-
|
10
|
-
unless application_configuration_content.match?(pattern)
|
11
|
-
inject_into_class(
|
12
|
-
application_configuration_path,
|
13
|
-
"Application",
|
14
|
-
%( config.autoload_paths << "\#{root}/app"\n)
|
15
|
-
)
|
16
|
-
end
|
17
|
-
|
18
|
-
tailwind_config_path = Rails.root.join("config/tailwind.config.js")
|
19
|
-
|
20
|
-
if tailwind_config_path.exist?
|
21
|
-
insert_into_file tailwind_config_path, after: "content: [" do
|
22
|
-
"\n './app/views/**/*.rb',"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
say "Phlex successfully installed!"
|
data/lib/tasks/phlex_tasks.rake
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :phlex do
|
4
|
-
desc "Install Phlex in the Rails application"
|
5
|
-
|
6
|
-
task :install do
|
7
|
-
install_file_path = File.expand_path("../install/phlex.rb", __dir__)
|
8
|
-
|
9
|
-
system "#{RbConfig.ruby} bin/rails app:template LOCATION=#{install_file_path}"
|
10
|
-
end
|
11
|
-
end
|