HTML templates for Bootstrap components.

See http://getbootstrap.com/components/

Introduced classes

class BSAlert

html :: BSAlert

A Bootstrap alert component.
class BSBadge

html :: BSBadge

A Bootstrap badge component.
class BSBreadCrumbs

html :: BSBreadCrumbs

A Bootstrap breadcrumbs component.
abstract class BSComponent

html :: BSComponent

Bootstrap component abstraction.
class BSIcon

html :: BSIcon

A Boostrap icon.
class BSLabel

html :: BSLabel

A Bootstrap label component.
class BSPageHeader

html :: BSPageHeader

A Bootstrap page header component.
class BSPanel

html :: BSPanel

A Bootstrap panel component.
abstract class HTMLList

html :: HTMLList

An abstract HTML list.
class Header

html :: Header

A <h1> to <h6> tag.
class ListItem

html :: ListItem

A <li> tag.
class OrderedList

html :: OrderedList

A <ol> list tag.
class UnorderedList

html :: UnorderedList

A <ul> list tag.

All class definitions

class BSAlert

html $ BSAlert

A Bootstrap alert component.
class BSBadge

html $ BSBadge

A Bootstrap badge component.
class BSBreadCrumbs

html $ BSBreadCrumbs

A Bootstrap breadcrumbs component.
abstract class BSComponent

html $ BSComponent

Bootstrap component abstraction.
class BSIcon

html $ BSIcon

A Boostrap icon.
class BSLabel

html $ BSLabel

A Bootstrap label component.
class BSPageHeader

html $ BSPageHeader

A Bootstrap page header component.
class BSPanel

html $ BSPanel

A Bootstrap panel component.
abstract class HTMLList

html $ HTMLList

An abstract HTML list.
class Header

html $ Header

A <h1> to <h6> tag.
class ListItem

html $ ListItem

A <li> tag.
class OrderedList

html $ OrderedList

A <ol> list tag.
class UnorderedList

html $ UnorderedList

A <ul> list tag.
package_diagram html::bootstrap bootstrap template template html::bootstrap->template core core template->core ...core ... ...core->core a_star-m a_star-m a_star-m->html::bootstrap

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module template

template :: template

Basic template system

Children

module a_star-m

a_star-m

# HTML templates for Bootstrap components.
#
# See http://getbootstrap.com/components/
module bootstrap

import template

# Bootstrap component abstraction.
#
# Mainly used to factoryze CSS treatments.
# Can be used in the future to handle generic stuff like attributes or escaping.
#
# TODO merge with html::HTMTag without init conflict?
# HTMLTag requires the main init to pass a tagname,
# this was so much verbose here.
abstract class BSComponent
	super Template

	# CSS classes to add on this element.
	var css_classes = new Array[String] is optional

	# Render `self` css clases as a `class` attribute.
	fun render_css_classes: String do
		if css_classes.is_empty then return ""
		return " class=\"{css_classes.join(" ")}\""
	end
end

# A `<a>` tag.
#
# Not really a Bootstrap component but used in other components
# that it required its own abstraction.
#
# Example:
# ~~~
# var lnk = new Link("http://nitlanguage.org", "Nit")
# assert lnk.write_to_string == "<a href=\"http://nitlanguage.org\">Nit</a>"
# ~~~
#
# Creates a link with a title attribute:
# ~~~
# lnk = new Link("http://nitlanguage.org", "Nit", "Nit homepage")
# assert lnk.write_to_string == "<a href=\"http://nitlanguage.org\" title=\"Nit homepage\">Nit</a>"
# ~~~
class Link
	super BSComponent
	autoinit(href, text, title, css_classes)

	# URL pointed by this link.
	var href: String is writable

	# Displayed text.
	var text: Writable is writable

	# Optional title.
	var title: nullable String = null is optional, writable

	redef fun rendering do
		add "<a{render_css_classes} href=\"{href}\""
		var title = self.title
		if title != null then add " title=\"{title.html_escape}\""
		add ">{text}</a>"
	end
end

# A `<h1>` to `<h6>` tag.
#
# Not really a Bootstrap component but used in other components
# that it required its own abstraction.
#
# Example:
# ~~~
# var h1 = new Header(1, "Title")
# assert h1.write_to_string == "<h1>Title</h1>"
# ~~~
#
# With subtext:
# ~~~
# var h6 = new Header(6, "Title", "with subtext")
# assert h6.write_to_string == "<h6>Title<small>with subtext</small></h6>"
# ~~~
class Header
	super BSComponent
	autoinit(level, text, subtext, id, css_classes)

	# Header level between 1 and 6.
	var level: Int

	# Displayed text.
	var text: Writable

	# Optional subtext.
	var subtext: nullable Writable = null is optional, writable

	# Optional id.
	var id: nullable String = null is optional, writable

	redef fun rendering do
		add "<h{level}{render_css_classes}>{text.write_to_string}"
		var subtext = self.subtext
		if subtext != null then add "<small>{subtext.write_to_string}</small>"
		add "</h{level}>"
	end
end

# An abstract HTML list.
#
# Many Bootstrap components are built around a HTML list.
#
# Used to factorize behavior between OrderedList and UnorderedList.
abstract class HTMLList
	super BSComponent
	autoinit(items, css_classes)

	# A list contains `<li>` tags as children.
	#
	# See ListItem.
	var items = new Array[ListItem] is optional

	# Adds a new ListItem to `self`.
	fun add_li(item: ListItem) do items.add item

	# Does `self` contains no items?
	fun is_empty: Bool do return items.is_empty
end

# A `<ol>` list tag.
#
# Example:
#
# ~~~
# var lst = new OrderedList
# lst.add_li(new ListItem("foo"))
# lst.add_li(new ListItem("bar"))
# lst.add_li(new ListItem("baz"))
#
# assert lst.write_to_string == """
# <ol>
# <li>foo</li>
# <li>bar</li>
# <li>baz</li>
# </ol>
# """
# ~~~
class OrderedList
	super HTMLList

	redef fun rendering do
		addn "<ol{render_css_classes}>"
		for item in items do add item
		addn "</ol>"
	end
end

# A `<ul>` list tag.
#
# Example:
#
# ~~~
# var lst = new UnorderedList
# lst.add_li(new ListItem("foo"))
# lst.add_li(new ListItem("bar"))
# lst.add_li(new ListItem("baz"))
#
# assert lst.write_to_string == """
# <ul>
# <li>foo</li>
# <li>bar</li>
# <li>baz</li>
# </ul>
# """
# ~~~
class UnorderedList
	super HTMLList

	redef fun rendering do
		addn "<ul{render_css_classes}>"
		for item in items do add item
		addn "</ul>"
	end
end

# A `<li>` tag.
class ListItem
	super BSComponent
	autoinit(text, css_classes)

	# Content to display in this list item.
	var text: Writable is writable

	redef fun rendering do addn "<li{render_css_classes}>{text.write_to_string}</li>"
end

# A Boostrap icon.
#
# See http://getbootstrap.com/components/#glyphicons
#
# Example:
#
# ~~~
# var icon = new BSIcon("star")
# assert icon.write_to_string == "<span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span>"
# ~~~
class BSIcon
	super BSComponent
	autoinit(icon, css_classes)

	# Glyphicon name to display.
	#
	# See full list at http://getbootstrap.com/components/#glyphicons.
	var icon: String

	init do css_classes.add "glyphicon glyphicon-{icon}"

	redef fun rendering do
		add "<span{render_css_classes} aria-hidden=\"true\"></span>"
	end
end

# A Bootstrap breadcrumbs component.
#
# See http://getbootstrap.com/components/#breadcrumbs
#
# Example:
#
# ~~~
# var bc = new BSBreadCrumbs
# bc.add_li(new ListItem("foo"))
# bc.add_li(new ListItem("bar"))
# bc.add_li(new ListItem("baz"))
#
# assert bc.write_to_string == """
# <ol class=\"breadcrumbs\">
# <li>foo</li>
# <li>bar</li>
# <li class=\"active\">baz</li>
# </ol>
# """
# ~~~
class BSBreadCrumbs
	super OrderedList

	init do css_classes.add "breadcrumbs"

	redef fun rendering do
		items.last.css_classes.add "active"
		super
	end
end

# A Bootstrap label component.
#
# See http://getbootstrap.com/components/#labels
#
# Example:
#
# ~~~
# var lbl = new BSLabel("danger", "Danger!")
# assert lbl.write_to_string == "<span class=\"label label-danger\">Danger!</span>"
# ~~~
class BSLabel
	super BSComponent
	autoinit(color, text, css_classes)

	# Class used to change the color of the label.
	#
	# Can be one of `default`, `primary`, `success`, `info`, `warning` or `danger`.
	var color: String

	# Text to display in the label.
	var text: Writable

	init do css_classes.add "label label-{color}"

	redef fun rendering do
		add "<span{render_css_classes}>{text.write_to_string}</span>"
	end
end

# A Bootstrap badge component.
#
# See http://getbootstrap.com/components/#badges
#
# Example:
#
# ~~~
# var b = new BSBadge("42 messages")
# assert b.write_to_string == "<span class=\"badge\">42 messages</span>"
# ~~~
class BSBadge
	super BSComponent
	autoinit(text, css_classes)

	# Text to display in the label.
	var text: Writable

	init do css_classes.add "badge"

	redef fun rendering do
		add "<span{render_css_classes}>{text.write_to_string}</span>"
	end
end

# A Bootstrap page header component.
#
# See http://getbootstrap.com/components/#page-header
#
# Example:
#
# ~~~
# var h = new BSPageHeader("Welcome")
# assert h.write_to_string == """
# <div class=\"page-header\">
# Welcome
# </div>
# """
# ~~~
class BSPageHeader
	super BSComponent
	autoinit(text, css_classes)

	# Text to display as title.
	var text: Writable

	init do css_classes.add "page-header"

	redef fun rendering do
		addn "<div{render_css_classes}>"
		addn text.write_to_string
		addn "</div>"
	end
end

# A Bootstrap alert component.
#
# See http://getbootstrap.com/components/#alerts
#
# Example:
#
# ~~~
# var alert = new BSAlert("danger", "Danger!")
# assert alert.write_to_string == """
# <div class="alert alert-danger">
# Danger!
# </div>
# """
# ~~~
class BSAlert
	super BSComponent
	autoinit(color, text, is_dismissible, css_classes)

	# Class used to change the color of the alert.
	#
	# Can be one of `primary`, `success`, `info`, `warning` or `danger`.
	var color: String

	# Text to display in the alert.
	var text: Writable

	# Can the alert be dismissed by clicking the close button?
	#
	# See http://getbootstrap.com/components/#alerts-dismissible
	#
	# Default is `false`.
	var is_dismissible = false is optional, writable

	init do css_classes.add "alert alert-{color}"

	redef fun rendering do
		addn "<div{render_css_classes}>"
		if is_dismissible then
			add "<button type=\"button\" class=\"close\" data-dismiss=\"alert\""
			add "aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span>"
			addn "</button>"
		end
		addn text.write_to_string
		addn "</div>"
	end
end

# A Bootstrap panel component.
#
# See http://getbootstrap.com/components/#panels
#
# Example:
#
# ~~~
# var p = new BSPanel("default", body = "Panel content")
#
# assert p.write_to_string == """
# <div class="panel panel-default">
# <div class="panel-body">
# Panel content
# </div>
# </div>
# """
# ~~~
#
# Panel with heading:
#
# ~~~
# p = new BSPanel("danger", heading = "Panel heading", body = "Panel content")
#
# assert p.write_to_string == """
# <div class="panel panel-danger">
# <div class="panel-heading">
# Panel heading
# </div>
# <div class="panel-body">
# Panel content
# </div>
# </div>
# """
# ~~~
class BSPanel
	super BSComponent
	autoinit(color, heading, body, footer, css_classes)

	# Panel color.
	#
	# Can be one of `default`, `primary`, `success`, `info`, `warning` or `danger`.
	var color: String is writable

	# Panel header if any.
	var heading: nullable Writable = null is optional, writable

	# Body to display in the panel.
	var body: nullable Writable = null is optional, writable

	# Panel footer is any.
	var footer: nullable Writable = null is optional, writable

	init do css_classes.add "panel panel-{color}"

	redef fun rendering do
		addn "<div{render_css_classes}>"
		var heading = self.heading
		if heading != null then
			addn "<div class=\"panel-heading\">"
			addn heading.write_to_string
			addn "</div>"
		end
		var body = self.body
		if body != null then
			addn "<div class=\"panel-body\">"
			addn body.write_to_string
			addn "</div>"
		end
		var footer = self.footer
		if footer != null then
			addn "<div class=\"panel-footer\">"
			addn footer.write_to_string
			addn "</div>"
		end
		addn "</div>"
	end
end
lib/html/bootstrap.nit:15,1--471,3