render_erb 0.0.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 +7 -0
- data/lib/render_erb.rb +22 -0
- metadata +40 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 98278f9e16aeec38abd4ef0b4fbf818b29b42e5bfcb30d1426c74f997627e3bc
|
|
4
|
+
data.tar.gz: 483dc809d4a10756c382ae9f13809ab3226b9852cb6c43b1ffe3c446ba2461ee
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 972ef762f9b856d18ad54701485029f7846dc47308ca067f46bcead3cff7c54cf245a8a230b4c5e564a2af7d57a381dabd8e0c274e52ca3e12abe52e3f25cc16
|
|
7
|
+
data.tar.gz: 3d286f8fc78ce9f535274154cbe49259110fff195d49c2286cdff4c2b45ad6bc6bc5c7a1f0f6ac364e850598906a3a26de8c7fd3c18cc1a9b56f6c73bb09a6bb
|
data/lib/render_erb.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# render_template
|
|
2
|
+
# allow user of gem to access this method.
|
|
3
|
+
# render_template "post", post: post
|
|
4
|
+
|
|
5
|
+
require "erb"
|
|
6
|
+
|
|
7
|
+
module RenderErb
|
|
8
|
+
def render_template(file_path, **locals)
|
|
9
|
+
file_with_ext = add_file_extension(file_path)
|
|
10
|
+
file_content = File.read(file_with_ext)
|
|
11
|
+
template = ERB.new(file_content)
|
|
12
|
+
bind = binding
|
|
13
|
+
locals.each do |k, v|
|
|
14
|
+
bind.local_variable_set(k, v)
|
|
15
|
+
end
|
|
16
|
+
template.result(bind)
|
|
17
|
+
end
|
|
18
|
+
private
|
|
19
|
+
def add_file_extension(file_path)
|
|
20
|
+
file_path.gsub(".html.erb", "") + ".html.erb"
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: render_erb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Indigo
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: A great gem to render ERB templates with locals
|
|
13
|
+
email: indigo@tech.tut
|
|
14
|
+
executables: []
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- lib/render_erb.rb
|
|
19
|
+
homepage: https://rubygems.org/gems/render_erb
|
|
20
|
+
licenses:
|
|
21
|
+
- MIT
|
|
22
|
+
metadata: {}
|
|
23
|
+
rdoc_options: []
|
|
24
|
+
require_paths:
|
|
25
|
+
- lib
|
|
26
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
27
|
+
requirements:
|
|
28
|
+
- - ">="
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: '0'
|
|
31
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
requirements: []
|
|
37
|
+
rubygems_version: 3.6.9
|
|
38
|
+
specification_version: 4
|
|
39
|
+
summary: A simple to use gem for rendering erb with locals
|
|
40
|
+
test_files: []
|