erbx 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +57 -0
  3. data/lib/erbx.rb +29 -0
  4. data/lib/erbx/version.rb +3 -0
  5. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e31bdf6421cebb1ec8d4527078e6459370107053b322536b26caadb41d11810
4
+ data.tar.gz: 3d739c286468a2b39f8444343deaaddd7ae19b93e4c4796389080c2b8e244c2a
5
+ SHA512:
6
+ metadata.gz: d39a67f89f6c707cbf127911842966fffaaa5ddc5aee7a97278d6381bcb2d20a1473f8531fb68b11e8b9638f887d7227c25213b54f134ff101449d1e4f806608
7
+ data.tar.gz: 83b240ba9ab750b85fe6ba064b3c672d277015402502804649fbffa643af20a13b7b395f03a635cf3e92cc6467317ed9b847b8336fb8626a4b82acf03134f6d3
@@ -0,0 +1,57 @@
1
+ # ERBX - ERB Extended with Pretty Tags
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/erbx.svg)](https://badge.fury.io/rb/erbx)
4
+ [![Build Status](https://github.com/DannyBen/erbx/workflows/Test/badge.svg)](https://github.com/DannyBen/erbx/actions?query=workflow%3ATest)
5
+
6
+ ---
7
+
8
+ ERBX is a tiny extension to ERB allowing these tags:
9
+
10
+ - `{{ ... }}` as an equivalent to `<%= ... %>`
11
+ - `(( ... ))` as an equivalent to `<%- ... %>`
12
+
13
+ ---
14
+
15
+ Installation
16
+ --------------------------------------------------
17
+
18
+ ```
19
+ $ gem install erbx
20
+ ```
21
+
22
+ Usage
23
+ --------------------------------------------------
24
+
25
+ Given this ERBX templalte:
26
+
27
+ ```
28
+ # example/template.md
29
+ ((
30
+ # Any ruby code can go here
31
+ today = Time.now.strftime "%B %d, %Y"
32
+ dice = [rand(6) + 1, rand(6) + 1]
33
+ ))
34
+
35
+ This roll of a dice happened on {{ today }}.
36
+ (( if dice[0] == dice[1] ))
37
+ Congratulations, its a double: {{ dice }}
38
+ (( else ))
39
+ You rolled {{ dice }}
40
+ (( end ))
41
+ ```
42
+
43
+
44
+ ```ruby
45
+ # Render example
46
+ require 'erbx'
47
+
48
+ template = ERBX.load 'example/template.md'
49
+ p template.class
50
+ #=> ERB
51
+
52
+ puts template.result
53
+ #=>
54
+ #=> This roll of a dice happened on April 24, 2020.
55
+ #=> You rolled [4, 2]
56
+ ```
57
+
@@ -0,0 +1,29 @@
1
+ require 'erb'
2
+ require 'erbx/version'
3
+
4
+ class ERBX
5
+ class << self
6
+ attr_reader :content
7
+
8
+ def load(filename)
9
+ new File.read filename
10
+ end
11
+
12
+ def new(content)
13
+ erb_content = expose_erb_tags content
14
+ ERB.new(erb_content, trim_mode: '%-')
15
+ end
16
+
17
+ private
18
+
19
+ def expose_erb_tags(content)
20
+ content
21
+ .gsub("((", "<%-")
22
+ .gsub("))", "-%>")
23
+ .gsub("{{", "<%=")
24
+ .gsub("}}", "%>")
25
+ end
26
+ end
27
+ end
28
+
29
+
@@ -0,0 +1,3 @@
1
+ class ERBX
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erbx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Danny Ben Shitrit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Extended ERB with prettier tags
14
+ email: db@dannyben.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/erbx.rb
21
+ - lib/erbx/version.rb
22
+ homepage: https://github.com/dannyben/erbx
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.4.0
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: ERB Extra
45
+ test_files: []