Class: TemplateBuilder
- Inherits:
-
Object
- Object
- TemplateBuilder
- Defined in:
- lib/csspress/template_builder.rb
Overview
TemplateBuilder is used to populate a template with a StyleSheet.
TemplateBuilder excepts a StyleSheet object and a template file. The template file contains erb tags that specify the layout of the output StyleSheet. TemplateBuilder will output the porulated template using the .publish() method.
If the template file supplied cannot be read an IOError is raised
Example:
ss = StyleSheet.new ( "foo.css" )
tb = TemplateBuilder.new ( ss )
puts tb.publish # output compressed version of ss
Constant Summary collapse
- TEMPLATE_DIR =
"/../templates/"
- DEFAULT =
"default.csst"
Instance Attribute Summary collapse
-
#style_sheet ⇒ Object
readonly
Style sheet to publish.
Instance Method Summary collapse
-
#initialize(style_sheet, template = DEFAULT) ⇒ TemplateBuilder
constructor
Create a new TemplateBuilder for style_sheet using template.
-
#publish ⇒ Object
Publish StyleSheet using template.
Constructor Details
#initialize(style_sheet, template = DEFAULT) ⇒ TemplateBuilder
Create a new TemplateBuilder for style_sheet using template.
38 39 40 41 |
# File 'lib/csspress/template_builder.rb', line 38 def initialize( style_sheet, template=DEFAULT ) @style_sheet = style_sheet @template = File.dirname(__FILE__) + TEMPLATE_DIR + template end |
Instance Attribute Details
#style_sheet ⇒ Object (readonly)
Style sheet to publish
32 33 34 |
# File 'lib/csspress/template_builder.rb', line 32 def style_sheet @style_sheet end |
Instance Method Details
#publish ⇒ Object
Publish StyleSheet using template. IOError raised if specified cannot be read.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/csspress/template_builder.rb', line 48 def publish begin template = File.read(@template) engin = ERB.new(template) t = engin.result(binding()) # Chomp the trailing newline t.gsub(/\n$/,'') rescue raise IOError, "Could not use requested template file: #{@template}" end end |