Module: HtmlGrid::TemplateMethods

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

Constant Summary collapse

CONTENT =
nil
FOOT =
nil
HEAD =
nil
META_TAGS =
[]
LEGACY_INTERFACE =
true
CSS_FILES =
[]
JAVASCRIPTS =
[]
@@local_doc_dir =
File.join(Dir.pwd, 'doc')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_inline(ressource) ⇒ Object



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

def TemplateMethods.get_inline(ressource)
  return nil unless ressource
  local_file = File.join(@@local_doc_dir, URI(ressource).path)
  File.exist?(local_file) ? File.read(local_file) : nil
end

Instance Method Details

#__standard_component(model, klass) ⇒ Object



78
79
80
81
82
# File 'lib/htmlgrid/template.rb', line 78

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

#content(model, session = nil) ⇒ Object



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

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


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/htmlgrid/template.rb', line 45

def css_link(context, path=@lookandfeel.resource(:css))
	properties = {
		"rel"		=>	"stylesheet",
		"type"	=>	"text/css",
		"async"	=>	"true",
		'href'	=>	path,
	}
    if (content = TemplateMethods.get_inline(path))
      properties.delete('href')
      context.style(properties) { content }
    else
      context.link(properties)
    end
end


59
60
61
62
63
64
65
# File 'lib/htmlgrid/template.rb', line 59

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



69
70
71
# File 'lib/htmlgrid/template.rb', line 69

def dynamic_html_headers(context)
	''
end

#foot(model, session = nil) ⇒ Object



72
73
74
# File 'lib/htmlgrid/template.rb', line 72

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

#head(model, session = nil) ⇒ Object



75
76
77
# File 'lib/htmlgrid/template.rb', line 75

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

#html_head(context, &block) ⇒ Object



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

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

#javascripts(context) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/htmlgrid/template.rb', line 95

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



106
107
108
109
110
# File 'lib/htmlgrid/template.rb', line 106

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

#onload=(script) ⇒ Object



111
112
113
# File 'lib/htmlgrid/template.rb', line 111

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

#other_html_headers(context) ⇒ Object



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

def other_html_headers(context)
	dynamic_html_headers(context)
end

#template_html(context, &block) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
# File 'lib/htmlgrid/template.rb', line 117

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



128
129
130
# File 'lib/htmlgrid/template.rb', line 128

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

#title(context) ⇒ Object



131
132
133
# File 'lib/htmlgrid/template.rb', line 131

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

#to_html(context) ⇒ Object



134
135
136
137
138
# File 'lib/htmlgrid/template.rb', line 134

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