dot_why 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dot_why.rb +69 -35
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6fb94638063c0d9a67d3b79a0bbdd7e49764fde
|
4
|
+
data.tar.gz: 4f1dda2ccdf62014e3f061e6a28911cc8da77293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41b8237b838df21a51e6bc5af28d6ad205f39ca33a9b7690c42d641f94b37616ed7bea4bf2b11b4b7b9c1871f2abe5ab31e3ce3d4b5aa3a973b533858981b2c3
|
7
|
+
data.tar.gz: 97993ed44ea0610e210941c551a9b232048cfb2e71d1eb8f9a073fdd4c6e682b6448dab69b2eae49c3b6b1f01da1990b0daa3f2afa0b9f57e4b35dd8fac89db2
|
data/lib/dot_why.rb
CHANGED
@@ -8,17 +8,25 @@ module Dot_Why
|
|
8
8
|
|
9
9
|
class << self # ================================================================
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
attr_reader :sections
|
12
|
+
|
13
|
+
def def_sections *args
|
14
|
+
@sections ||= {}
|
15
|
+
args.each { |v|
|
16
|
+
@sections[v] = true
|
17
|
+
}
|
17
18
|
end
|
18
19
|
|
20
|
+
alias_method :def_section, :def_sections
|
21
|
+
|
19
22
|
end # ==========================================================================
|
20
23
|
|
21
|
-
|
24
|
+
def_section :main
|
25
|
+
|
26
|
+
def def_sections *args
|
27
|
+
self.class.def_sections *args
|
28
|
+
end
|
29
|
+
alias_method :def_section, :def_sections
|
22
30
|
|
23
31
|
def initialize raw_file, *args
|
24
32
|
@file = file = File.expand_path(raw_file).sub(".rb", "") + '.rb'
|
@@ -30,44 +38,70 @@ module Dot_Why
|
|
30
38
|
@file
|
31
39
|
end
|
32
40
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
elsif (pos == :replace)
|
40
|
-
@_blocks[name] = [b]
|
41
|
-
else
|
42
|
-
@_blocks[name].push(b)
|
43
|
-
end
|
44
|
-
else
|
45
|
-
(@_blocks[name] || []).each do |bl|
|
46
|
-
bl.call
|
47
|
-
end
|
48
|
-
end
|
41
|
+
def eval_main
|
42
|
+
eval(File.read("#{@file}"), nil, @file, 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
def content
|
46
|
+
main
|
49
47
|
end
|
50
48
|
|
51
|
-
def
|
52
|
-
@
|
53
|
-
|
54
|
-
@
|
49
|
+
def use_file name
|
50
|
+
@files ||= {}
|
51
|
+
raise "File already used: #{name.inspect}" if @files[name]
|
52
|
+
@files[name] = true
|
53
|
+
name
|
55
54
|
end
|
56
55
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
56
|
+
def section name, pos = :bottom, *args, &b
|
57
|
+
raise "Section not defined: #{name}" if !self.class.sections[name]
|
58
|
+
|
59
|
+
if not block_given?
|
60
|
+
(@_blocks[name] || []).each { |bl| bl.call }
|
61
|
+
return
|
62
|
+
end
|
63
|
+
|
64
|
+
@_blocks[name] ||= []
|
65
|
+
if (pos == :top)
|
66
|
+
@_blocks[name].unshift(b)
|
67
|
+
elsif (pos == :replace)
|
68
|
+
@_blocks[name] = [b]
|
60
69
|
else
|
61
|
-
|
70
|
+
@_blocks[name].push(b)
|
62
71
|
end
|
72
|
+
end # === def section
|
73
|
+
|
74
|
+
def view_name
|
75
|
+
@view_name ||= begin
|
76
|
+
base = File.basename(main_file).sub(".rb", '')
|
77
|
+
dir = File.dirname(main_file)
|
78
|
+
"#{dir}/#{base}"
|
79
|
+
end
|
63
80
|
end
|
64
81
|
|
65
|
-
|
66
|
-
|
82
|
+
# === automate some tags =================================================================
|
83
|
+
|
84
|
+
def stylesheet name
|
85
|
+
filename = if name[/\:/]
|
86
|
+
name
|
87
|
+
else
|
88
|
+
if name['/']
|
89
|
+
"#{name}.css?#{STAMP}"
|
90
|
+
else
|
91
|
+
"/css/#{name}.css?#{STAMP}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
link(:rel=>'stylesheet', :type=>'text/css', :href=>use_file(filename), :media=>'screen')
|
67
95
|
end
|
68
96
|
|
69
|
-
def
|
70
|
-
|
97
|
+
def script *args
|
98
|
+
if args.size == 1 && args.first.is_a?(String)
|
99
|
+
name = args.first
|
100
|
+
full = "#{name}.js"
|
101
|
+
super(:type=>"text/javascript", :src=>"#{use_file full}")
|
102
|
+
else
|
103
|
+
super
|
104
|
+
end
|
71
105
|
end
|
72
106
|
|
73
107
|
end # === Layout
|