theo-rails 0.1.0 → 0.1.2

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: 6681a53dbf50c16328a4e7fdd336e4796f816f2b378144ac1fa159a77b84f271
4
- data.tar.gz: 8a8dd2a5918fb52dbf7a7aa193654921cf91615ea031017c595be10c445a8555
3
+ metadata.gz: a47ba0ddf03dcfcfb0f712ada5463e4bc2226ce299b818c41f931eaf37337be1
4
+ data.tar.gz: c595cc7b8548ccb085f8c11467fe01d611cdd56492bce78097c15d907d2c4e2c
5
5
  SHA512:
6
- metadata.gz: 3b09043ae8e7a6fdd0291f50aff9ae4b3c902b9bec12799c3578f5b01fdb4eae40a0a36fe02c145c577c9afca4e0e54418c51b164c7eeff70d40d32c9ac6a689
7
- data.tar.gz: 17f3b1401babf88a7849db263b3ec502037a6b8c91fa23a181cbe1be9f0d60eaf8f2a097abee6404aeff84066400d1d14ab8710489079ae029d6376c49f80644
6
+ metadata.gz: 8086955a23ee2389321b560033282045a56595366299739b3767454e74121c24b2a3bfd50bff46840984d7ca099a8205d80ebb0e0e6ac8536a81ef2e31e28978
7
+ data.tar.gz: eccbd592a2d340674a8226d9d77cacabfd47aa99256edd2a6f14350a4408f1ad68efa04215d259244074224713d6282152b53fa42c488ade521ecc59554d2539
@@ -1,2 +1,4 @@
1
- <%# locals: (form:, name:, **attributes) -%>
1
+ <%# locals: (form: nil, name:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <%= form.email_field name, **attributes %>
@@ -1,4 +1,6 @@
1
1
  <%# locals: (url: nil, model:nil, **attributes) -%>
2
2
  <%= form_with url:, model:, html: attributes do |form| %>
3
- <% yield form %>
3
+ <% provide(form:) do %>
4
+ <%= yield form %>
5
+ <% end %>
4
6
  <% end %>
@@ -1,4 +1,6 @@
1
- <%# locals: (form:, name:, **attributes) -%>
1
+ <%# locals: (form: nil, name:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <% if (block = yield).present? %>
3
5
  <%= form.label name, **attributes do %><%= block %><% end %>
4
6
  <% else %>
@@ -1,3 +1,5 @@
1
- <%# locals: (form:, name:, **attributes) -%>
1
+ <%# locals: (form: nil, name:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <%= form.number_field name, **attributes %>
3
5
 
@@ -1,3 +1,5 @@
1
- <%# locals: (form:, name:, options:, **attributes) -%>
1
+ <%# locals: (form: nil, name:, options:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <%= form.select name, options, {}, **attributes %>
3
5
 
@@ -1,3 +1,5 @@
1
- <%# locals: (form:, value:, **attributes) -%>
1
+ <%# locals: (form: nil, value: nil, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <%= form.submit value, **attributes %>
3
5
 
@@ -1,3 +1,5 @@
1
- <%# locals: (form:, name:, **attributes) -%>
1
+ <%# locals: (form: nil, name:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <%= form.text_area name, **attributes %>
3
5
 
@@ -1,2 +1,4 @@
1
- <%# locals: (form:, name:, **attributes) -%>
1
+ <%# locals: (form: nil, name:, **attributes) -%>
2
+ <% form ||= inject(:form) %>
3
+
2
4
  <%= form.text_field name, **attributes %>
@@ -0,0 +1,18 @@
1
+ module Theo
2
+ module Rails
3
+ module Helpers
4
+ def provide(**args)
5
+ @theo_context ||= {}
6
+ @theo_context.merge!(args)
7
+
8
+ yield
9
+
10
+ @theo_context.except!(args.keys)
11
+ end
12
+
13
+ def inject(key)
14
+ @theo_context&.[](key)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,9 +1,10 @@
1
1
  module Theo
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
- initializer 'initialize theo template handler' do
4
+ initializer 'initialize theo' do
5
5
  ActiveSupport.on_load(:action_view) do
6
6
  ::ActionView::Template.register_template_handler :theo, :'erb.theo', Theo.new
7
+ include ::Theo::Rails::Helpers
7
8
  end
8
9
  end
9
10
  end
@@ -42,12 +42,12 @@ module Theo
42
42
  collection = ", collection: #{collection}#{as}"
43
43
  end
44
44
 
45
- arg = "|#{attributes.delete(:arg)}|" if attributes[:arg]
45
+ yields = "|#{attributes.delete(:yields)}|" if attributes[:yields]
46
46
 
47
47
  attributes.transform_values! { |value| attribute(value) }
48
48
 
49
49
  if content
50
- output = "<%= render '#{partial}', {#{attributes.map {|k,v| "'#{k}': #{v}"}.join(', ')}} do #{arg || ''} %>#{process(content)}<% end %>"
50
+ output = "<%= render '#{partial}', {#{attributes.map {|k,v| "'#{k}': #{v}"}.join(', ')}} do #{yields || ''} %>#{process(content)}<% end %>"
51
51
  else
52
52
  output = "<%= render partial: '#{partial}'#{collection}, locals: {#{attributes.map {|k,v| "'#{k}': #{v}"}.join(', ')}} %>"
53
53
  end
data/lib/theo-rails.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'theo-rails/theo'
2
+ require 'theo-rails/helpers'
2
3
  require 'theo-rails/engine' if defined?(Rails::Engine)
3
4
  require 'theo-rails/railtie' if defined?(Rails::Railtie)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarek Lipski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-12 00:00:00.000000000 Z
11
+ date: 2024-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: HTML-like template language for Rails with natural partial syntax
14
14
  email: jarek@jareklipski.com
@@ -26,6 +26,7 @@ files:
26
26
  - app/views/application/_text_field.html.erb
27
27
  - lib/theo-rails.rb
28
28
  - lib/theo-rails/engine.rb
29
+ - lib/theo-rails/helpers.rb
29
30
  - lib/theo-rails/railtie.rb
30
31
  - lib/theo-rails/theo.rb
31
32
  homepage: https://github.com/loomchild/theo-rails