Project

hypertext

0.0
No commit activity in last 3 years
No release in over 3 years
Hypertext authoring with Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Hypertext

Hypertext authoring

Description

Hypertext allows you to write HTML from Ruby.

Usage

A basic example would look like this:

html = Hypertext.new do |h|
  h.tag :div, "data-index-number" => 123, class: "greeting" do
    h.tag :h1 do
      h.text "hello world"
    end

    h.tag :hr

    h.tag :p do
      h.text "nice to meet you"
    end
  end
end

puts html.to_s

# <div data-index-number="123" class="greeting">
#   <h1>
#     hello world
#   </h1>
#   <hr />
#   <p>
#     nice to meet you
#   </p>
# </div>

DSL

As an experimental feature, Hypertext provides a DSL for describing an HTML document in a way that resembles Markaby.

require "hypertext"
require "hypertext/dsl"

person_name = "Foo Bar"

html = Hypertext::DSL.new do
  form action: "/", method: "post" do
    input name: "person[name]", value: person_name
    input type: "submit"
  end
end

puts html.to_s

# <form action="/" method="post">
#   <input name="person[name]" value="Foo Bar" />
#   <input type="submit" />
# </form>

Installation

$ gem install hypertext