sculpt 0.1.04 → 0.1.05

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sculpt.rb CHANGED
@@ -24,45 +24,50 @@ class Sculpt
24
24
  #
25
25
 
26
26
  class << self
27
- attr_accessor :pretty
28
- end
29
-
30
- def self.pretty?
31
- @pretty
32
- end
27
+ attr_accessor :pretty, :smart_attrs
28
+
29
+ def pretty? # just because that looks nicer
30
+ @pretty
31
+ end
32
+
33
+ def smart_attrs? # and here
34
+ @smart_attrs
35
+ end
36
+
37
+ def render_doc(str = '', &block)
38
+ puts self.make_doc(str,&block)
39
+ end
33
40
 
34
- def self.render_doc(str = '', &block)
35
- puts self.make_doc(str,&block)
36
- end
41
+ def make_doc(str = '', &block)
42
+ if str.length > 0
43
+ proc = str.to_proc
44
+ else
45
+ proc = block
46
+ end
37
47
 
38
- def self.make_doc(str = '', &block)
39
- if str.length > 0
40
- proc = str.to_proc
41
- else
42
- proc = block
48
+ self.make do
49
+ doctype
50
+ html(&proc)
51
+ end
43
52
  end
44
-
45
- self.make do
46
- doctype
47
- html(&proc)
53
+
54
+ def render(str = '', &block)
55
+ puts self.make(str,&block)
48
56
  end
49
- end
50
57
 
51
- def self.render(str = '', &block)
52
- puts self.make(str,&block)
53
- end
58
+ def make(str = '', &block)
59
+ if str.length > 0
60
+ proc = str.to_proc
61
+ else
62
+ proc = block
63
+ end
54
64
 
55
- def self.make(str = '', &block)
56
- if str.length > 0
57
- proc = str.to_proc
58
- else
59
- proc = block
65
+ result = Sculpture.new
66
+ result.instance_eval(&proc)
67
+ result.generate_html
60
68
  end
61
-
62
- result = Sculpture.new
63
- result.instance_eval(&proc)
64
- result.generate_html
65
69
  end
66
70
  end
67
71
 
68
- Sculpt.pretty = true # pretty print by default
72
+ Sculpt.pretty = true # pretty print by default
73
+ Sculpt.smart_attrs = true # replace underscores in syms acting as attr keys (iss#2)
@@ -42,7 +42,7 @@ class Tag < ElementContainer
42
42
  n = @name.to_s
43
43
  open = "<#{n}"
44
44
  @attrs.each do |k, v|
45
- open += " #{k}=\"#{v}\""
45
+ open += " #{attr_replace(k)}=\"#{v}\""
46
46
  end
47
47
  open += '>'
48
48
  return open if @singleton
@@ -14,9 +14,16 @@ module SculptHelpers
14
14
  return attrs.merge(extra) if extra.kind_of? Hash
15
15
  attrs
16
16
  end
17
+
18
+ def attr_replace(a)
19
+ if a.is_a? Symbol and Sculpt.smart_attrs?
20
+ return a.to_s.gsub('_','-')
21
+ end
22
+ a
23
+ end
17
24
  end
18
25
 
19
- # some awesome string additions.
26
+ # some string additions.
20
27
 
21
28
  class String
22
29
  # this one from mynyml/unindent on github
@@ -28,7 +35,7 @@ class String
28
35
  self.replace(self.unindent)
29
36
  end
30
37
 
31
- # this awesome one by me
38
+ # this one by me
32
39
  def to_proc
33
40
  eval "Proc.new do\n#{self}\nend"
34
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sculpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.04
4
+ version: 0.1.05
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-28 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "Sculpt is an HTML generator in Ruby.\n Syntax is everything."
15
15
  email: lexy0202@gmail.com