Module: HtmlGrid::TemplateMethods

Included in:
DivTemplate, Template
Defined in:
lib/htmlgrid/template.rb

Constant Summary collapse

CONTENT =
nil
FOOT =
nil
HEAD =
nil
META_TAGS =
[]
CSS_FILES =
[]
JAVASCRIPTS =
[]

Instance Method Summary collapse

Instance Method Details

#__standard_component(model, klass) ⇒ Object



64
65
66
67
68
# File 'lib/htmlgrid/template.rb', line 64

def __standard_component(model, klass)
	if(klass.is_a?(Class))
		klass.new(model, @session, self)
	end
end

#content(model, session = nil) ⇒ Object



52
53
54
# File 'lib/htmlgrid/template.rb', line 52

def content(model, session=nil)
	__standard_component(model, self::class::CONTENT)
end


37
38
39
40
41
42
43
44
# File 'lib/htmlgrid/template.rb', line 37

def css_link(context, path=@lookandfeel.resource(:css))
	properties = {
		"rel"		=>	"stylesheet",
		"type"	=>	"text/css",
		"href"	=>	path,
	}
	context.link(properties)
end


45
46
47
48
49
50
51
# File 'lib/htmlgrid/template.rb', line 45

def css_links(context, path=@lookandfeel.resource(:css))
	links = self.class.const_get(:CSS_FILES).collect { |key| 
		css_link(context, @lookandfeel.resource(key)) 
	}
	links.push(css_link(context, path)) if(path)
	links.join
end

#dynamic_html_headers(context) ⇒ Object



55
56
57
# File 'lib/htmlgrid/template.rb', line 55

def dynamic_html_headers(context)
	''
end

#foot(model, session = nil) ⇒ Object



58
59
60
# File 'lib/htmlgrid/template.rb', line 58

def foot(model, session=nil)
	__standard_component(model, self::class::FOOT)
end

#head(model, session = nil) ⇒ Object



61
62
63
# File 'lib/htmlgrid/template.rb', line 61

def head(model, session=nil)
	__standard_component(model, self::class::HEAD)
end

#html_head(context, &block) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/htmlgrid/template.rb', line 69

def html_head(context, &block)
	context.head {
		if(block_given?)
			block.call
		end.to_s <<
		title(context) << 
		meta_tags(context) <<
		other_html_headers(context) <<
		css_links(context) <<
		javascripts(context)
	}
end

#javascripts(context) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/htmlgrid/template.rb', line 81

def javascripts(context)
	jscripts = self.class.const_get(:JAVASCRIPTS).collect { |key|
		properties = {
			"language"	=>	"JavaScript",
			"type"			=>	"text/javascript",
			"src"				=>	@lookandfeel.resource_global(:javascript, "#{key}.js"),
		}		
		context.script(properties)
	}
	jscripts.join
end

#meta_tags(context) ⇒ Object



92
93
94
95
96
# File 'lib/htmlgrid/template.rb', line 92

def meta_tags(context)
	self::class::META_TAGS.inject('') { |inj, properties|
		inj << context.meta(properties)
	}
end

#onload=(script) ⇒ Object



97
98
99
# File 'lib/htmlgrid/template.rb', line 97

def onload=(script)
	@attributes['onload'] = script
end

#other_html_headers(context) ⇒ Object



100
101
102
# File 'lib/htmlgrid/template.rb', line 100

def other_html_headers(context)
	dynamic_html_headers(context)
end

#template_html(context, &block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/htmlgrid/template.rb', line 103

def template_html(context, &block)
	args = {}
	if(dtd = @lookandfeel.lookup(:DOCTYPE))
		args.store('DOCTYPE', dtd)
	end
	context.html(args) {
		html_head(context) << context.body(@attributes) {
			template_tags(context, &block)
		}
	}
end

#template_tags(context, &block) ⇒ Object



114
115
116
# File 'lib/htmlgrid/template.rb', line 114

def template_tags(context, &block)
	block.call
end

#title(context) ⇒ Object



117
118
119
# File 'lib/htmlgrid/template.rb', line 117

def title(context)
	context.title { @lookandfeel.lookup(:html_title) }
end

#to_html(context) ⇒ Object



120
121
122
123
124
# File 'lib/htmlgrid/template.rb', line 120

def to_html(context)
	template_html(context) {
		super(context)
	}
end