Giter Club home page Giter Club logo

erbx's Introduction

ERBX - ERB Extended with Pretty Tags

Gem Version Build Status


ERBX is a tiny extension to ERB allowing these tags:

  • {{ ... }} as an equivalent to <%= ... %> (print ruby code)
  • (( ... )) as an equivalent to <%- ... -%> (run ruby code)

Both tag pairs are configurable.


Installation

$ gem install erbx

Usage

Given this ERBX templalte:

# example/template.md
((
# Any ruby code can go here
today = Time.now.strftime "%B %d, %Y"
dice = [rand(6) + 1, rand(6) + 1]
))

This roll of a dice happened on {{ today }}.
(( if dice[0] == dice[1] ))
Congratulations, its a double: {{ dice }}
(( else ))
You rolled {{ dice }}
(( end ))

Render it with ERBX.new, which returns an ERB instance, after replacing the extended tags - {{ }} and (( )) - with their ERB equivalents.

# Render example
require 'erbx'

template = ERBX.load 'example/template.md'
p template.class
#=> ERB

puts template.result
#=> 
#=> This roll of a dice happened on April 24, 2020.
#=> You rolled [4, 2]

Custom Tags

If you wish to use different tags in your template, you can provide them using these four options:

  • code_open - default ((
  • code_close - default ))
  • output_open - default {{
  • output_close - default }}

For example:

# Render example with options
require 'erbx'

template = ERBX.load 'example/template2.md', code_open: '===[', code_close: ']==='
puts template.result_with_hash number: rand(100..999)
#=> This template only uses output tags, and uses data provided by the caller.
#=> This is useful when the file may contain (( markers like these )) that are
#=> not intended to be interpreted as code.
#=> 
#=> Random number: 938

Contributing / Support

If you experience any issue, have a question or a suggestion, or if you wish to contribute, feel free to open an issue.


erbx's People

Contributors

dannyben avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.