Project

iron-web

0.0
No commit activity in last 3 years
No release in over 3 years
Html builder, color helper class and url parser/builder class for use in Rails projects or other web-based content generation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.6

Runtime

 Project Readme

GEM: iron-web¶ ↑

Written by Rob Morris @ Irongaze Consulting LLC (irongaze.com)

DESCRIPTION¶ ↑

A set of classes useful in the generation of HTML content.

CLASSES¶ ↑

  • Url - a url parsing and manipulation class

    >> url = Url.build('/home')
    >> url.to_s
    => '/home'
    >> url.params[:key] = 'some value'
    >> url.to_s
    => '/home?key=some+value'
    >> url.make_absolute(false, 'google.com')
    => 'http://google.com/home?key=some+value'
    >> url.make_absolute(true, 'bing.com', 8080)
    => 'https://bing.com:8080/home?key=some+value'
  • Color - an RGB/A color manipulation class, useful in generating CSS etc.

    >> rgb('#f00').to_s  # Parse a color string into a Color then render it
    => '#FF0000'
    >> rgb('#f00').darken(0.5).to_s  # Darken bright red 50%
    => '#800000'
    >> rgb('#f00').blend('#0f0', 0.5).to_s  # Blend pure red and pure green, get medium yellow
    => "#807F00"
  • Html / Html::Element - a builder-syntax HTML generation class set

    >> html = Html.build do |html|
    >>   html.div(:id => 'primary') {
    >>     html.h1('Title-town!')
    >>   }
    >>   html.div(:id => 'secondary') {|div|
    >>     div.style = 'text-align: center;'
    >>     div.text! "My body text..."
    >>   }
    >> end
    >> puts html
    => <div id="primary">
    =>   <h1>
    =>     Title-town!
    =>   </h1>
    => </div>
    => <div id="secondary" style="text-align: center;">
    =>   My body text...
    => </div>

SYNOPSIS¶ ↑

To use:

require 'iron-web'

Sample usage of all components:

Html.build do |html|
  html.h1('Hello World') {|h1|
    h1.style = "color: #{rgb('#f00').darken};"
  }

  html.hr

  homepage = Url.parse('http://irongaze.com')
  homepage.fragment = 'incoming'
  html.a('Say hello to my log file', :href => homepage)
end

Which would result in:

<h1 style="color: #CC0000;">
  Hello World
</h1>
<hr>
<a href="http://irongaze.com#incoming">Say hello to my log file</a>

Notice the darkened and correctly formatted CSS color value and the newly fragment-ized url.

HTML elements are built by calling their tag name on the Html instance. Similarly, element attributes are added by calling the attribute’s name on the element instance, or by simply setting them during construction.

REQUIREMENTS¶ ↑

  • iron-extensions gem

INSTALL¶ ↑

To install, simply run:

sudo gem install iron-web

RVM users can skip the sudo:

gem install iron-web