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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dot_why.rb +69 -35
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39eb8e2e9d1c535efe41ff75c1db523e8d2d2105
4
- data.tar.gz: 71f1e98fcd52dbebe24278e43808d15b6fc2cb80
3
+ metadata.gz: b6fb94638063c0d9a67d3b79a0bbdd7e49764fde
4
+ data.tar.gz: 4f1dda2ccdf62014e3f061e6a28911cc8da77293
5
5
  SHA512:
6
- metadata.gz: b463ed51aca8275ce7057890b56774f1555991f3f435750d1b789921ca24e91befe91f7f58f8bd991ef6e87bc794df20f80dbf34b8eefcec7e300a526a9be7e0
7
- data.tar.gz: be89a4120da9a7ffe4eea11c6f2b23678b5ccee163065482473949a80fbad7ef20389306031a3671168d22e34d6322d01b3edd49b09842599e75042a6c2be43d
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
- def blocks *args
12
- args.each do |word|
13
- define_method(word.to_sym) do |pos = :bottom, &b|
14
- block word, pos, &b
15
- end
16
- end
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
- blocks :main
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 block raw_name, pos = :bottom, *args, &b
34
- name = raw_name.to_sym
35
- if (b)
36
- @_blocks[name] ||= []
37
- if (pos == :top)
38
- @_blocks[name].unshift(b)
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 styles *args, &b
52
- @_link_type = :css
53
- block :styles, *args, &b
54
- @_link_type = nil
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 link *args
58
- if (@_link_type == :css && args.length == 1 && args[0].instance_of?(String))
59
- super(:rel=>"stylesheet", :type=>"text/css", :href=>args[0])
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
- super
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
- def eval_main
66
- eval(File.read("#{@file}"), nil, @file, 1)
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 content
70
- main
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_why
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99