Class: Dot_Why::Template
- Inherits:
-
Erector::Widget
- Object
- Erector::Widget
- Dot_Why::Template
show all
- Includes:
- Cosmo, Diet_Dot, Ok
- Defined in:
- lib/Ok.rb,
lib/Cosmo.rb,
lib/dot_why.rb,
lib/Diet_Dot.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Diet_Dot
#dot, #dot_array, #dot_i, #dot_tertiary, #dot_v, #inline_rawdot, #rawdot, #var
Methods included from Cosmo
#inline_var, #var, #var_block
Methods included from Ok
#add_mtime, #applet, #as_this_life_menu, #on_off, #span_as
Constructor Details
#initialize(raw_file, *args) ⇒ Template
Returns a new instance of Template.
31
32
33
34
35
|
# File 'lib/dot_why.rb', line 31
def initialize raw_file, *args
@file = file = File.expand_path(raw_file).sub(".rb", "") + '.rb'
@_blocks = {}
super(*args)
end
|
Class Attribute Details
.sections ⇒ Object
Returns the value of attribute sections.
11
12
13
|
# File 'lib/dot_why.rb', line 11
def sections
@sections
end
|
Class Method Details
.def_section ⇒ Object
20
21
22
23
24
25
|
# File 'lib/dot_why.rb', line 20
def def_sections *args
@sections ||= {}
args.each { |v|
@sections[v] = true
}
end
|
.def_sections(*args) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/dot_why.rb', line 13
def def_sections *args
@sections ||= {}
args.each { |v|
@sections[v] = true
}
end
|
Instance Method Details
#content ⇒ Object
58
59
60
|
# File 'lib/dot_why.rb', line 58
def content
main
end
|
#def_sections(*args) ⇒ Object
Also known as:
def_section
26
27
28
|
# File 'lib/dot_why.rb', line 26
def def_sections *args
self.class.def_sections *args
end
|
#eval_main ⇒ Object
41
42
43
|
# File 'lib/dot_why.rb', line 41
def eval_main
eval(File.read(@file.to_s), nil, @file, 1)
end
|
#file_stamp ⇒ Object
98
99
100
|
# File 'lib/dot_why.rb', line 98
def file_stamp
@file_stamp ||= Time.now.to_i
end
|
#main_file ⇒ Object
37
38
39
|
# File 'lib/dot_why.rb', line 37
def main_file
@file
end
|
#partial(file_or_dir, file = nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/dot_why.rb', line 45
def partial file_or_dir, file = nil
file = if file
dir = Dir.exist?(file_or_dir) ?
file_or_dir :
File.dirname(file_or_dir)
File.join(dir, file)
else
file_or_dir
end
eval(File.read(file), nil, file, 1)
end
|
#script(*args) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/dot_why.rb', line 115
def script *args
if args.size == 1 && args.first.is_a?(String)
name = args.first
full = "#{name}.js?#{file_stamp}"
super(:type=>"text/javascript", :src=>"#{use_file full}")
else
super
end
end
|
#section(name, pos = :bottom, *args, &b) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/dot_why.rb', line 70
def section name, pos = :bottom, *args, &b
raise "Section not defined: #{name}" if !self.class.sections[name]
if not block_given?
(@_blocks[name] || []).each { |bl| bl.call }
return
end
@_blocks[name] ||= []
if (pos == :top)
@_blocks[name].unshift(b)
elsif (pos == :replace)
@_blocks[name] = [b]
else
@_blocks[name].push(b)
end
end
|
#stylesheet(name) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/dot_why.rb', line 102
def stylesheet name
filename = if name[/\:/]
name
else
if name['/']
"#{name}.css?#{file_stamp}"
else
"/css/#{name}.css?#{file_stamp}"
end
end
link(:rel=>'stylesheet', :type=>'text/css', :href=>use_file(filename), :media=>'screen')
end
|
#use_file(raw_name) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/dot_why.rb', line 62
def use_file raw_name
name = raw_name.split('?').first
@files ||= {}
raise "File already used: #{name.inspect}" if @files[name]
@files[name] = true
raw_name
end
|
#view_name ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/dot_why.rb', line 88
def view_name
@view_name ||= begin
base = File.basename(main_file).sub(".rb", '')
dir = File.basename(File.dirname main_file)
"#{dir}/#{base}"
end
end
|