dyny 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/LICENSE +165 -0
- data/README.md +134 -0
- data/Rakefile +33 -0
- data/dyny.gemspec +32 -0
- data/lib/dyny/helper.rb +129 -0
- data/lib/dyny/railtie.rb +9 -0
- data/lib/dyny/template_handler.rb +13 -0
- data/lib/dyny/version.rb +13 -0
- data/lib/dyny.rb +6 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac39f6b0676a5fbe97a7c27892edc4566add5abd2a7c60afecb26aec8dc1feae
|
4
|
+
data.tar.gz: e6e05b5303feb4fb7a28d3d22f08108319b7e0169317b220dba6bcbe6a08cfe6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b8d79ae31f52706869df25ed7a7010746c7edfbee827a194a553304089e5731b49710577c71fd3176dc11cc9ed09ce85e9010d2b2c9ef40b7968aa3201d9d6b
|
7
|
+
data.tar.gz: a67634f5e1ef2a798d897af6c9ae42d996880897b6ee18fc50e81d7d3d65d2193230cfba4e17016b995861e8bb6aa51c1c7a0059c840700bcd69f06bd5096796
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.rubocop.yml
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.4
|
data/LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# Introducing Dyny
|
2
|
+
|
3
|
+
Dyny is a tiny framework for writing dynamic Rails views directly in Ruby.
|
4
|
+
Typically, Rails views, are written in
|
5
|
+
[ERB](https://guides.rubyonrails.org/layouts_and_rendering.html),
|
6
|
+
[HAML](https://haml.info/) or [Slim](https://github.com/slim-template/slim).
|
7
|
+
However there are situations where you'd prefer to write regular ruby code
|
8
|
+
without having to cope with [Tag
|
9
|
+
Helpers](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html)
|
10
|
+
at every call. This is where Dyny comes in.
|
11
|
+
|
12
|
+
A quick and trivial example: Having `MessagesController` and an action
|
13
|
+
`hello_world`, you can write a file `app/views/messages/hello_world.html.dyny`
|
14
|
+
with the contents:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
h1 'Hello world'
|
18
|
+
div class: 'card mb-3' do
|
19
|
+
div class: 'card-body' do
|
20
|
+
para "I'm inside a Bootstrap card."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
- Use directory structures similar to ERB views
|
26
|
+
- The file extension is `.html.dyny`
|
27
|
+
- Call HTML elements as methods and nest them using blocks. There are three special cases:
|
28
|
+
- Since the method name `p` is already taken, use `para` to generate a `<p>` tag.
|
29
|
+
- Since the method names `label` and `select` are taken by Rails, use
|
30
|
+
`tag.label` and `tag.select` instead.
|
31
|
+
- Arguments given to Dyny HTML helper methods are passed to the [Rails `tag`
|
32
|
+
helper](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag),
|
33
|
+
for instance `class` in the example above.
|
34
|
+
- If you don't want a HTML tag, but output plain text, use `concat`. See examples below.
|
35
|
+
|
36
|
+
**Dyny was tested with Rails 7.**
|
37
|
+
|
38
|
+
# But dynamic views are bad?
|
39
|
+
|
40
|
+
Rails views are meant to merely display data that was already pre-processed
|
41
|
+
elsewhere, such as helpers or controller actions. However, as your application
|
42
|
+
gets very complex, there may be situations where adhering to that principle
|
43
|
+
leads to code scattered all over your application. Also, for rapid prototyping,
|
44
|
+
you might wanna start writing your first proof-of-concept code directly into the
|
45
|
+
view. This is where dyny jumps in to fill the gap and lets you write views
|
46
|
+
directly in Ruby.
|
47
|
+
|
48
|
+
Dyny does not prevent you from writing most of your views in ERB or HAML. The
|
49
|
+
file name ending of the view decides which processor is used. If your file ends
|
50
|
+
with `.html.erb`, you write ERB HTML; if it ends with `.html.dyny`, you can
|
51
|
+
write plain Ruby with the help of Dyny.
|
52
|
+
|
53
|
+
# Installation
|
54
|
+
|
55
|
+
1. Add the gem to your Gemfile: `gem 'dyny'`
|
56
|
+
2. Run `bundle` to install it.
|
57
|
+
|
58
|
+
# Usage
|
59
|
+
|
60
|
+
## In a template
|
61
|
+
|
62
|
+
Simply have the file name of your view end with `.html.dyny` and write plain
|
63
|
+
ruby in it, as shown in the example above.
|
64
|
+
|
65
|
+
## In `render` or `render_to_string`
|
66
|
+
|
67
|
+
You may speficy `type: :dyny` in your render call to have Rails process your string with Dyny. Using `inline`, you may supply a string containing ruby.
|
68
|
+
|
69
|
+
As an example: in your controller, you may call:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
render_to_string(
|
73
|
+
type: :dyny,
|
74
|
+
locals: { foo: :bar },
|
75
|
+
inline: <<~RUBY
|
76
|
+
h1 'Hello world'
|
77
|
+
RUBY
|
78
|
+
)
|
79
|
+
```
|
80
|
+
|
81
|
+
# Examples
|
82
|
+
|
83
|
+
## A trivial index page
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
h1 'All users'
|
87
|
+
ul do
|
88
|
+
@users.each do |current_user|
|
89
|
+
li current_user.name
|
90
|
+
end
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
## Working with simple_form and bootstrap
|
95
|
+
|
96
|
+
This illustrates working with Bootstrap and the popular
|
97
|
+
`[SimpleForm](https://github.com/heartcombo/simple_form)` gem. For a better
|
98
|
+
overview, we first save the HTML generated by `simple_form_for` into the local
|
99
|
+
variable `form_html` and use `concat` to output it later.
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
div class: 'card card-body' do
|
103
|
+
form_html = simple_form_for :test do |f|
|
104
|
+
concat(f.input(:fun))
|
105
|
+
div(f.input(:stuff), class: 'mb-3')
|
106
|
+
concat f.submit
|
107
|
+
end
|
108
|
+
concat form_html
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
The result is a form with two fields and a submit button.
|
113
|
+
|
114
|
+
# Differences to the Arbre gem
|
115
|
+
|
116
|
+
This project aims to replace [Arbre](https://github.com/activeadmin/arbre) which
|
117
|
+
has similar intentions. The key differences to Arbre are:
|
118
|
+
|
119
|
+
- Dyny is much smaller and simpler than Arbre but achieves the same features.
|
120
|
+
- Dyny supports using controller instance variable in views while Arbre does not
|
121
|
+
- Dyny properly uses the `ActionView` buffer, supporting calls to `concat` or
|
122
|
+
`capture`. This means that Dyny fully supports gems making use of these
|
123
|
+
features, such as [SimpleForm](https://github.com/heartcombo/simple_form),
|
124
|
+
while Arbre breaks such gems because it uses its own buffer.
|
125
|
+
- Where Arbre uses `text_node`, Dyny lets you use the native Rails method
|
126
|
+
`concat` to output raw text.
|
127
|
+
- Arbre has its own `Context` concept while Dyny does not. To have Dyny
|
128
|
+
generated HTML saved to a string variable, use Rails' `render_to_string`
|
129
|
+
method instead, see example above.
|
130
|
+
|
131
|
+
# Contributing
|
132
|
+
|
133
|
+
You are welcome to contribute to this project via the regular fork and pull
|
134
|
+
request procedure.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require_relative 'lib/dyny/version'
|
5
|
+
|
6
|
+
task :gemspec do
|
7
|
+
specification = Gem::Specification.new do |s|
|
8
|
+
s.name = 'dyny'
|
9
|
+
s.version = Dyny::Version::LABEL
|
10
|
+
s.author = ['Sandro Kalbermatter']
|
11
|
+
s.summary = 'A tiny framework for writing dynamic Rails views directly in Ruby'
|
12
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
13
|
+
s.executables = []
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
s.required_ruby_version = '>= 3.0.0'
|
16
|
+
s.license = 'LGPL-3.0-or-later'
|
17
|
+
s.homepage = 'https://github.com/kalsan/dyny'
|
18
|
+
s.metadata = {
|
19
|
+
'source_code_uri' => 'https://github.com/kalsan/dyny',
|
20
|
+
'documentation_uri' => 'https://github.com/kalsan/dyny'
|
21
|
+
|
22
|
+
}
|
23
|
+
|
24
|
+
# Dependencies
|
25
|
+
s.add_runtime_dependency 'rails' # Tested with Rails 7, but olders may work. TBD.
|
26
|
+
end
|
27
|
+
|
28
|
+
File.open('dyny.gemspec', 'w') do |f|
|
29
|
+
f.puts('# DO NOT EDIT')
|
30
|
+
f.puts("# This file is auto-generated via: 'rake gemspec'.\n\n")
|
31
|
+
f.write(specification.to_ruby.strip)
|
32
|
+
end
|
33
|
+
end
|
data/dyny.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# DO NOT EDIT
|
2
|
+
# This file is auto-generated via: 'rake gemspec'.
|
3
|
+
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: dyny 0.0.3 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "dyny".freeze
|
9
|
+
s.version = "0.0.3"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.metadata = { "documentation_uri" => "https://github.com/kalsan/dyny", "source_code_uri" => "https://github.com/kalsan/dyny" } if s.respond_to? :metadata=
|
13
|
+
s.require_paths = ["lib".freeze]
|
14
|
+
s.authors = ["Sandro Kalbermatter".freeze]
|
15
|
+
s.date = "2022-12-07"
|
16
|
+
s.files = [".gitignore".freeze, ".ruby-version".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "dyny.gemspec".freeze, "lib/dyny.rb".freeze, "lib/dyny/helper.rb".freeze, "lib/dyny/railtie.rb".freeze, "lib/dyny/template_handler.rb".freeze, "lib/dyny/version.rb".freeze]
|
17
|
+
s.homepage = "https://github.com/kalsan/dyny".freeze
|
18
|
+
s.licenses = ["LGPL-3.0-or-later".freeze]
|
19
|
+
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
|
20
|
+
s.rubygems_version = "3.2.33".freeze
|
21
|
+
s.summary = "A tiny framework for writing dynamic Rails views directly in Ruby".freeze
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
s.specification_version = 4
|
25
|
+
end
|
26
|
+
|
27
|
+
if s.respond_to? :add_runtime_dependency then
|
28
|
+
s.add_runtime_dependency(%q<rails>.freeze, [">= 0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<rails>.freeze, [">= 0"])
|
31
|
+
end
|
32
|
+
end
|
data/lib/dyny/helper.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
module Dyny
|
2
|
+
# This module is injected into every code that runs in Dyny.
|
3
|
+
module Helper
|
4
|
+
# Intial HTML Tag set was extracted from https://github.dev/activeadmin/arbre
|
5
|
+
# The tags `label` and `select` were removed because they collide with Rails helpers and are rarely used in practice. Use `concat tag.label` instead.
|
6
|
+
HTML_TAGS = %i[a
|
7
|
+
abbr
|
8
|
+
address
|
9
|
+
area
|
10
|
+
article
|
11
|
+
aside
|
12
|
+
audio
|
13
|
+
b
|
14
|
+
base
|
15
|
+
bdo
|
16
|
+
blockquote
|
17
|
+
body
|
18
|
+
br
|
19
|
+
button
|
20
|
+
canvas
|
21
|
+
caption
|
22
|
+
cite
|
23
|
+
code
|
24
|
+
col
|
25
|
+
colgroup
|
26
|
+
command
|
27
|
+
datalist
|
28
|
+
dd
|
29
|
+
del
|
30
|
+
details
|
31
|
+
dfn
|
32
|
+
div
|
33
|
+
dl
|
34
|
+
dt
|
35
|
+
em
|
36
|
+
embed
|
37
|
+
fieldset
|
38
|
+
figcaption
|
39
|
+
figure
|
40
|
+
footer
|
41
|
+
form
|
42
|
+
h1 h2 h3 h4 h5 h6
|
43
|
+
head
|
44
|
+
header
|
45
|
+
hgroup
|
46
|
+
hr
|
47
|
+
html
|
48
|
+
i
|
49
|
+
iframe
|
50
|
+
img
|
51
|
+
input
|
52
|
+
ins
|
53
|
+
keygen
|
54
|
+
kbd
|
55
|
+
legend
|
56
|
+
li
|
57
|
+
link
|
58
|
+
main
|
59
|
+
map
|
60
|
+
mark
|
61
|
+
menu
|
62
|
+
menuitem
|
63
|
+
meta
|
64
|
+
meter
|
65
|
+
nav
|
66
|
+
noscript
|
67
|
+
object
|
68
|
+
ol
|
69
|
+
optgroup
|
70
|
+
option
|
71
|
+
output
|
72
|
+
param
|
73
|
+
pre
|
74
|
+
progress
|
75
|
+
q
|
76
|
+
s
|
77
|
+
samp
|
78
|
+
script
|
79
|
+
section
|
80
|
+
small
|
81
|
+
source
|
82
|
+
span
|
83
|
+
strong
|
84
|
+
style
|
85
|
+
sub
|
86
|
+
summary
|
87
|
+
sup
|
88
|
+
svg
|
89
|
+
table
|
90
|
+
tbody
|
91
|
+
td
|
92
|
+
textarea
|
93
|
+
tfoot
|
94
|
+
th
|
95
|
+
thead
|
96
|
+
time
|
97
|
+
title
|
98
|
+
tr
|
99
|
+
track
|
100
|
+
ul
|
101
|
+
var
|
102
|
+
video
|
103
|
+
wbr].freeze
|
104
|
+
|
105
|
+
# Uncomment the following lines to search for method name collisions.
|
106
|
+
# HTML_TAGS.each do |tag|
|
107
|
+
# begin
|
108
|
+
# send tag.to_sym
|
109
|
+
# puts "Clash! #{tag.inspect}"
|
110
|
+
# rescue ArgumentError
|
111
|
+
# puts "Clash! #{tag.inspect}"
|
112
|
+
# rescue NoMethodError
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
|
116
|
+
HTML_TAGS.each do |tag|
|
117
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
118
|
+
def #{tag}(...) # def form(...)
|
119
|
+
concat tag.#{tag}(...) # concat tag.form(...)
|
120
|
+
end # end
|
121
|
+
RUBY
|
122
|
+
end
|
123
|
+
|
124
|
+
# method name :p is already taken for printing purposes, therefore we make `para` generate <p> tags.
|
125
|
+
def para(...)
|
126
|
+
concat tag.p(...)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/lib/dyny/railtie.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Dyny
|
2
|
+
# This plugs into Rails and allows to handle app/views/foo/bar.html.rb templates
|
3
|
+
class TemplateHandler
|
4
|
+
def call(_template, source_code = nil)
|
5
|
+
return <<~RUBY
|
6
|
+
#{source_code}
|
7
|
+
return output_buffer
|
8
|
+
RUBY
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActionView::Template.register_template_handler(:dyny, Dyny::TemplateHandler.new)
|
data/lib/dyny/version.rb
ADDED
data/lib/dyny.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dyny
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sandro Kalbermatter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".ruby-version"
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- dyny.gemspec
|
39
|
+
- lib/dyny.rb
|
40
|
+
- lib/dyny/helper.rb
|
41
|
+
- lib/dyny/railtie.rb
|
42
|
+
- lib/dyny/template_handler.rb
|
43
|
+
- lib/dyny/version.rb
|
44
|
+
homepage: https://github.com/kalsan/dyny
|
45
|
+
licenses:
|
46
|
+
- LGPL-3.0-or-later
|
47
|
+
metadata:
|
48
|
+
documentation_uri: https://github.com/kalsan/dyny
|
49
|
+
source_code_uri: https://github.com/kalsan/dyny
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 3.0.0
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.2.33
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A tiny framework for writing dynamic Rails views directly in Ruby
|
69
|
+
test_files: []
|