lipsum 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ $:.unshift( "../lib" )
2
+ require 'lipsum'
3
+
4
+ puts Lipsum.paragraphs![2].to_html
5
+ puts "----------------------------------------------------"
6
+ puts Lipsum.words[10].to_html
7
+ puts "----------------------------------------------------"
8
+ puts Lipsum.new(true).bytes[128].to_html
9
+ puts "----------------------------------------------------"
10
+ puts Lipsum.lists![3].to_html
@@ -19,16 +19,12 @@ class Lipsum
19
19
  end
20
20
 
21
21
  def to_s
22
- r = ""
23
- Nokogiri::XML.parse(@lorem_ipsum.to_s).xpath('/div[@id="lipsum"]/p').each do |p|
24
- r << p.content.to_s.strip << "\n\n"
25
- end
26
- r
22
+ @lorem_ipsum.inner_text()
27
23
  end
28
24
  alias_method :to_string, :to_s
29
25
 
30
26
  def to_html
31
- Nokogiri::XML.parse(@lorem_ipsum.to_s).xpath('/div[@id="lipsum"]/p').to_s
27
+ self.to_s.split( /\n/ ).map{ |e| "<p>#{e}</p>\n" }.join()
32
28
  end
33
29
 
34
30
  private
@@ -36,10 +32,11 @@ class Lipsum
36
32
  def generate
37
33
  opts = {'amount' => @amount, 'what' => @what}
38
34
  opts['start'] = 1 if @start
39
- response = Net::HTTP.post_form(URI.parse('http://lipsum.com/feed/html'), opts)
40
- html = Nokogiri::HTML.parse(response.body)
35
+ response = Net::HTTP.post_form(URI.parse('http://lipsum.com/feed/xml'), opts)
36
+
37
+ xml = Nokogiri::XML.parse(response.body)
41
38
 
42
- @lorem_ipsum = html.xpath('//div[@id="lipsum"]')
39
+ @lorem_ipsum = xml.xpath('//lipsum')
43
40
  end
44
41
  end
45
42
 
@@ -71,16 +68,11 @@ class Lipsum
71
68
  end
72
69
 
73
70
  def to_s
74
- r = ""
75
- Nokogiri::XML.parse(@lorem_ipsum.to_s).xpath('/div[@id="lipsum"]/ul').each do |ul|
76
- r << ul.content.to_s.strip.split(/\n/).map { |x| "* " << x }.join( "\n" )
77
- r << "\n\n"
78
- end
79
- r
71
+ @lorem_ipsum.inner_text().split( /\n/ ).map{ |e| "- #{e}\n" }.join()
80
72
  end
81
73
 
82
74
  def to_html
83
- Nokogiri::XML.parse(@lorem_ipsum.to_s).xpath('/div[@id="lipsum"]/ul').to_s
75
+ "<ul>\n" + @lorem_ipsum.inner_text().split( /\n/ ).map{ |e| "<li>#{e}</li>\n" }.join() + "</ul>"
84
76
  end
85
77
  end
86
78
 
@@ -1,3 +1,3 @@
1
1
  class Lipsum
2
- VERSION="1.1.0"
2
+ VERSION="1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lipsum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Lejeune
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-21 00:00:00 +02:00
12
+ date: 2009-10-14 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,6 +39,7 @@ files:
39
39
  - README.rdoc
40
40
  - AUTHORS
41
41
  - setup.rb
42
+ - examples/test.rb
42
43
  - lib/lipsum/version.rb
43
44
  - lib/lipsum.rb
44
45
  has_rdoc: true