Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ate

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ate

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Ate

Atractive Template Engine for minimalist people

Installation

$ gem install ate

Usage

template = Ate.parse("Hello World")
template.render #=> "Hello World"

Ruby code

Lines that start with % are evaluated as Ruby code.

% if true
  Hi
% else
  No, I won't display me
% end

As this is ruby code, you can comment as you has always done

% # I'm a comment.

And you can still doing any ruby thing: blocks, loops, etc.

% 3.times do |i|
  {{i}}
% end

Assignment

To print a variable just use {{ and }}

Send Variables

Send a variables as a hash in the parse method to the template so it can get them:

template = Ate.parse("Hello, this is {{user}}", user: "dog")
template.render #=> "Hello, this is dog"

Also, you can send other kinds of variables:

template = <<-EOT
  % items.each do |item|
    {{ item }}
  % end
EOT
parsed = Ate.parse(template, items: ["a", "b", "c"])
parsed.render #=> "a\nb\n\c"

You can even take advantage of do whatever operation inside the {{ }}

template = Ate.parse("The new price is: {{ price + 10 }}", price: 30)
template.render #=> "The new price is: 40"

Contexts

For send a particular context to your template, use the context key

user = User.new "Julio"
puts user.name #=> "Julio"
template = Ate.parse("Hi, I'm {{ context.name }}", context: user)
template.render #=> "Hi, I'm Julio"

Using files

Declare you file with .ate extension in the parse method

template = Ate.parse("example.ate")

Feel free to use any markup language like HTML

template = <<-EOT
  <h1>{{ main_title }}</h1>
  % posts.each do |post|
    <article>...</article>
  % end
EOT
parsed = Ate.parse(template, main_title: "h1 title!", posts: array_of_posts)

FAQs

Package last updated on 29 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc