rbhtml 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rbhtml.rb +41 -31
  2. metadata +4 -3
data/lib/rbhtml.rb CHANGED
@@ -1,35 +1,45 @@
1
1
  class String
2
- def strpush! push
3
- newstring = push + self
4
- self.replace(newstring)
5
- end
2
+ def strpush! push
3
+ newstring = push + self
4
+ self.replace(newstring)
5
+ end
6
6
  end
7
7
  class HTMLDocument
8
- private
9
- def refresh_full
10
- @full_doc = @open_doc + @close_doc
11
- end
12
- public
13
- def initialize
14
- @open_doc = "<html><body>"
15
- @close_doc = "</body></html>"
16
- @full_doc = @open_doc + @close_doc
17
- end
18
- def create_element tag, inner
19
- @open_doc += "<#{tag}>#{inner}"
20
- @close_doc.strpush!("</#{tag}>")
21
- refresh_full
22
- end
23
- def remove_element tag, inner
24
- @open_doc.gsub!("<#{tag}>#{inner}", "")
25
- @close_doc.gsub!("</#{tag}>", "")
26
- refresh_full
8
+ private
9
+ def refresh_full
10
+ @full_doc = @open_doc + @close_doc
11
+ end
12
+ def index_element tag, inner
13
+ @index_dict["#{tag}///#{@index_id}"] = "#{inner}"
14
+ end
15
+ public
16
+ def initialize
17
+ @open_doc = "<html><body>"
18
+ @close_doc = "</body></html>"
19
+ @full_doc = @open_doc + @close_doc
20
+ @index_dict = {}
21
+ @index_id = 0
22
+ end
23
+ def create_element tag, inner, attribute=false, value=false
24
+ if attribute and value
25
+ @open_doc += "<#{tag} #{attribute}='#{value}'>#{inner}</#{tag}>"
26
+ else
27
+ @open_doc += "<#{tag}>#{inner}</#{tag}>"
27
28
  end
28
- def remove_char char
29
- @open_doc.gsub!(">#{char}", ">")
30
- refresh_full
31
- end
32
- def to_s
33
- @full_doc
34
- end
35
- end
29
+ @index_id += 1
30
+ refresh_full
31
+ index_element tag, inner
32
+ end
33
+ def remove_element tag, inner
34
+ @open_doc.gsub!("<#{tag}>#{inner}", "")
35
+ @close_doc.gsub!("</#{tag}>", "")
36
+ refresh_full
37
+ end
38
+ def remove_char char
39
+ @open_doc.gsub!(">#{char}", ">")
40
+ refresh_full
41
+ end
42
+ def to_s
43
+ @full_doc
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbhtml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-02 00:00:00.000000000 Z
12
+ date: 2012-06-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: An HTML generator written in Ruby, many more features to come
14
+ description: An HTML generator written in Ruby. Added attributes to create_element
15
+ method. Removed bug where if you create two elements, the elements overlap.
15
16
  email: slmnwise@gmail.com
16
17
  executables: []
17
18
  extensions: []