votd 2.0.0 → 2.1.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.
data/.travis.yml CHANGED
@@ -9,5 +9,6 @@ notifications:
9
9
  recipients:
10
10
  - beakr@ninjanizr.com
11
11
  - doctorbh@ninjanizr.com
12
+ - main@seven7.flowdock.com
12
13
  on_success: always
13
14
  on_failure: always
data/CHANGELOG.md CHANGED
@@ -1,8 +1,18 @@
1
1
  # Changelog
2
- * March 30, 2010 2.0.0 release
3
- * New `copyright` attribute containing any copyright information provided
2
+ * March 31, 2012 (2.1.0)
3
+ * [Add] `.custom_html` method that takes a block of custom formatted
4
+ HTML to override the `.to_html` method.
5
+ * [Add] `.to_text` method that returns a text-formatted version
6
+ of the VotD.
7
+ Aliased to `.to_s`.
8
+ * [Add] `.custom_text` method that takes a block of custom formatted
9
+ text to override the `.to_text` method.
10
+ * [Add] `.translation` -> aliased to `.version`.
11
+
12
+ * March 30, 2012 2.0.0 release
13
+ * New `.copyright` attribute containing any copyright information provided
4
14
  by the VotD service. This may will cause any existing use of
5
- `Votd.BibleGateway.text` to lose copyright data unless you add it.
15
+ `Votd::BibleGateway.text` to lose copyright data unless you add it.
6
16
  (Previously, we were just using the copyright data that Bible Gateway
7
17
  appended to the end of the Bible text.)
8
18
  Bible Gateway requires that you add this copyright data.
data/README.md CHANGED
@@ -48,10 +48,14 @@ To use VotD in your code:
48
48
  votd.date # 2012-03-24
49
49
  votd.version # NIV
50
50
  votd.copyright # Copyright © ...
51
+
52
+ ### Outputting HTML
53
+
54
+ You can use the built-in formatted HTML:
51
55
 
52
- votd.to_html # <p class="votd-text">For by grace you are saved through faith...
56
+ votd.to_html
53
57
 
54
- Full text of HTML formatted VotD looks like the following
58
+ Which by default looks like the following:
55
59
 
56
60
  <p class="votd-text">For by grace you are saved through faith... it is not from works, so that no one can boast.</p>
57
61
  <p>
@@ -61,6 +65,44 @@ Full text of HTML formatted VotD looks like the following
61
65
 
62
66
  You can then use the provided CSS classes to style the VotD.
63
67
 
68
+ You may also provide custom HTML text by using the `.custom_html` method with a block:
69
+
70
+ votd.custom_html do |votd|
71
+ "<p>#{votd.reference} - #{votd.text} (#{votd.version})</p>"
72
+ end
73
+
74
+ `votd.to_html` now outputs:
75
+
76
+ <p>John 3:16 - For God so loved... (KJV)</p>
77
+
78
+ ### Outputting Text
79
+
80
+ You can use the built-in formatted Text:
81
+
82
+ votd.to_text
83
+
84
+ Which by default looks like the following:
85
+
86
+ For God so loved the world, that he gave his only begotten Son,
87
+ that whosoever believeth in him should not perish, but have
88
+ everlasting life. -- John 3:16 (KJV)
89
+
90
+ `.to_text` is also aliased to `.to_s`
91
+
92
+ You can provide custom Text formatting by using the `.custom_text` method with a block:
93
+
94
+ votd.custom_text do |votd|
95
+ "#{votd.reference}|#{votd.text}|#{votd.version}"
96
+ end
97
+
98
+ Which outputs:
99
+
100
+ John 3:16|For God so loved...|(KJV)
101
+
102
+ This returns the custom formatted text, or you can call the `.to_text` method
103
+ when ready, and your custom text will be output.
104
+
105
+ ## Command Line
64
106
  For command-line usage see [here](https://github.com/doctorbh/votd/wiki/Shell-Tool)
65
107
 
66
108
  ## Documentation
data/bin/votd CHANGED
@@ -7,9 +7,15 @@ require 'votd'
7
7
 
8
8
  votd = Votd::BibleGateway.new
9
9
 
10
- puts "===================================================="
11
- puts " VERSE OF THE DAY for #{votd.date.to_s}"
12
- puts "===================================================="
13
- puts votd.text
14
- puts "#{votd.reference} (#{votd.version})"
10
+ def banner(width = 78)
11
+ width = yield.size
12
+ puts "=" * width
13
+ puts yield
14
+ puts "=" * width
15
+ end
15
16
 
17
+ banner do
18
+ "VERSE OF THE DAY for #{votd.date.to_s}"
19
+ end
20
+
21
+ puts votd.to_text
data/lib/votd/base.rb CHANGED
@@ -10,7 +10,7 @@ module Votd
10
10
  attr_reader :text
11
11
 
12
12
  # @example
13
- # votd.reference # "Ephesians 2:8-9"
13
+ # votd.reference # "Ephesians 2:8-9"
14
14
  #
15
15
  # @return [String] the scripture reference.
16
16
  attr_reader :reference
@@ -22,12 +22,13 @@ module Votd
22
22
  attr_reader :date
23
23
 
24
24
  # @example
25
- # votd.version # "NIV"
25
+ # votd.version # "NIV"
26
26
  # @return [String] the bible translation used for this VotD
27
27
  attr_reader :version
28
+ alias_method :translation, :version
28
29
 
29
30
  # @example
30
- # votd.copyright # "Brought to you by BibleGateway.com. Copyright (C) . All Rights Reserved."
31
+ # votd.copyright # "Brought to you by BibleGateway.com. Copyright (C) . All Rights Reserved."
31
32
  # @return [String] any copyright information supplied by VotD provider
32
33
  attr_reader :copyright
33
34
 
@@ -38,10 +39,12 @@ module Votd
38
39
  # Initializes the class and retrieves the verse of the day.
39
40
  # @return [Base]
40
41
  def initialize
41
- @text = ""
42
- @reference = ""
43
- @copyright = nil
44
- @date = Date.today
42
+ @text = ""
43
+ @reference = ""
44
+ @copyright = nil
45
+ @date = Date.today
46
+ @custom_html = nil
47
+ @custom_text = nil
45
48
  get_votd
46
49
  end
47
50
 
@@ -53,16 +56,63 @@ module Votd
53
56
  # </p>
54
57
  #
55
58
  # This should provide sufficient hooks to style the CSS. If this is not
56
- # sufficient, you can build the HTML by hand using the individual data.
59
+ # sufficient, you can build the HTML by hand using the individual data,
60
+ # or use the {#custom_html} method to override the HTML format.
57
61
  #
58
62
  # @return [String] the VotD formatted as HTML
59
63
  def to_html
60
- html = "<p class=\"votd-text\">#{@text}</p>\n"
61
- html << "<p>\n"
62
- html << "<span class=\"votd-reference\"><strong>#{@reference}</strong></span>\n"
63
- html << "<span class=\"votd-version\"><em>(#{@version})</em></span>\n"
64
- html << "</p>\n"
65
- html
64
+ default_html = "<p class=\"votd-text\">#{@text}</p>\n"
65
+ default_html << "<p>\n"
66
+ default_html << "<span class=\"votd-reference\"><strong>#{@reference}</strong></span>\n"
67
+ default_html << "<span class=\"votd-version\"><em>(#{@version})</em></span>\n"
68
+ default_html << "</p>\n"
69
+ @custom_html ||= default_html
70
+ end
71
+
72
+ # Overrides the {#to_html} method with your own custom HTML. Use a block to specify your
73
+ # custom HTML.
74
+ # @example
75
+ # votd.custom_html do |votd|
76
+ # "<p>#{votd.reference} - #{votd.text} (#{votd.version})</p>"
77
+ # end
78
+ #
79
+ # # outputs:
80
+ # # <p>John 3:16 - For God so loved... (KJV)</p>
81
+ #
82
+ # This returns the custom formatted HTML, or you can call the {#to_html} method
83
+ # when ready and your custom HTML will be output.
84
+ #
85
+ # @return [String] the VotD formatted as custom HTML
86
+ def custom_html
87
+ @custom_html = yield(self)
88
+ end
89
+
90
+ # Returns the Verse of the Day formatted as plain text. e.g.
91
+ # For God so loved the world... -- John 3:16 (KJV)
92
+ #
93
+ # You can override this formatting with the {#custom_text} method.
94
+ # @return [String] the VotD formatted as plain text
95
+ def to_text
96
+ @custom_text ||= "#{@text} -- #{@reference} (#{@version})"
97
+ end
98
+ alias_method :to_s, :to_text
99
+
100
+ # Overrides the {#to_text} with your own custom text. Use a block to specify
101
+ # your custom text.
102
+ # @example
103
+ # votd.custom_text do |votd|
104
+ # "#{votd.reference}|#{votd.text}|#{votd.version}"
105
+ # end
106
+ #
107
+ # # outputs:
108
+ # John 3:16|For God so loved...|(KJV)
109
+ #
110
+ # This returns the custom formatted text, or you can call the {#to_text} method
111
+ # when ready, and your custom text will be output.
112
+ #
113
+ # @return [String] the VotD formatted as custom text
114
+ def custom_text
115
+ @custom_text = yield(self)
66
116
  end
67
117
 
68
118
  protected
@@ -76,4 +126,4 @@ module Votd
76
126
  end
77
127
 
78
128
  end
79
- end
129
+ end
data/lib/votd/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Votd
2
2
  # Gem version number
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
@@ -0,0 +1 @@
1
+ For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. -- John 3:16 (KJV)
@@ -0,0 +1 @@
1
+ <p>John 3:16|For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.|KJV</p>
@@ -0,0 +1 @@
1
+ John 3:16|For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.|KJV
@@ -0,0 +1 @@
1
+ If we confess our sins, he is faithful and just and will forgive us our sins and purify us from all unrighteousness. -- 1 John 1:9 (NIV)
@@ -0,0 +1 @@
1
+ <p>1 John 1:9|If we confess our sins, he is faithful and just and will forgive us our sins and purify us from all unrighteousness.|NIV</p>
@@ -0,0 +1 @@
1
+ 1 John 1:9|If we confess our sins, he is faithful and just and will forgive us our sins and purify us from all unrighteousness.|NIV
@@ -0,0 +1 @@
1
+ For by grace you are saved through faith... it is not from works, so that no one can boast. -- Ephesians 2:8-9 (NETBible)
@@ -0,0 +1 @@
1
+ <p>Ephesians 2:8-9|For by grace you are saved through faith... it is not from works, so that no one can boast.|NETBible</p>
@@ -0,0 +1 @@
1
+ Ephesians 2:8-9|For by grace you are saved through faith... it is not from works, so that no one can boast.|NETBible
@@ -15,9 +15,10 @@ describe "Votd::Base" do
15
15
  end
16
16
  end
17
17
 
18
- describe ".version" do
18
+ describe ".version / .translation" do
19
19
  it "returns the default bible version" do
20
- votd.version.should == "KJV"
20
+ votd.translation.should == "KJV"
21
+ votd.version.should == "KJV"
21
22
  end
22
23
  end
23
24
 
@@ -35,7 +36,39 @@ describe "Votd::Base" do
35
36
 
36
37
  describe ".to_html" do
37
38
  it "returns a HTML version" do
38
- votd.to_html.should == File.read(fixture("base.html"))
39
+ votd.to_html.should == read_fixture("base/base.html")
39
40
  end
40
41
  end
41
- end
42
+
43
+ describe ".custom_html" do
44
+ it "returns custom HTML and overrides the default .to_html formatting" do
45
+ html_from_block = votd.custom_html do |votd|
46
+ "<p>#{votd.reference}|#{votd.text}|#{votd.version}</p>"
47
+ end
48
+ desired_output = read_fixture("base/base_custom.html")
49
+ html_from_block.should == desired_output
50
+ votd.to_html.should == desired_output
51
+ end
52
+ end
53
+
54
+ describe ".to_text" do
55
+ it "returns a text-formatted version" do
56
+ votd.to_text.should == read_fixture("base/base.txt")
57
+ end
58
+
59
+ it "is aliased to .to_s" do
60
+ votd.to_s.should == read_fixture("base/base.txt")
61
+ end
62
+ end
63
+
64
+ describe ".custom_text" do
65
+ it "overrides the default.to_text formatting" do
66
+ text_from_block = votd.custom_text do |votd|
67
+ "#{votd.reference}|#{votd.text}|#{votd.version}"
68
+ end
69
+ desired_output = read_fixture("base/base_custom.txt")
70
+ text_from_block.should == desired_output
71
+ votd.to_text.should == desired_output
72
+ end
73
+ end
74
+ end
@@ -19,9 +19,10 @@ describe "Votd::BibleGateway" do
19
19
  end
20
20
  end
21
21
 
22
- describe ".version" do
22
+ describe ".version / .translation" do
23
23
  it "returns the correct bible version" do
24
- votd.version.should == "NIV"
24
+ votd.version.should == "NIV"
25
+ votd.translation.should == "NIV"
25
26
  end
26
27
  end
27
28
 
@@ -39,7 +40,38 @@ describe "Votd::BibleGateway" do
39
40
 
40
41
  describe ".to_html" do
41
42
  it "returns a HTML version" do
42
- votd.to_html.should == File.read(fixture("bible_gateway.html"))
43
+ votd.to_html.should == read_fixture("bible_gateway/bible_gateway.html")
43
44
  end
44
45
  end
45
- end
46
+
47
+ describe ".custom_html" do
48
+ it "overrides the default .to_html formatting" do
49
+ votd.custom_html do |votd|
50
+ "<p>#{votd.reference}|#{votd.text}|#{votd.version}</p>"
51
+ end
52
+ votd.to_html.should == read_fixture("bible_gateway/bible_gateway_custom.html")
53
+ end
54
+ end
55
+
56
+ describe ".to_text" do
57
+ it "returns a text-formatted version" do
58
+ votd.to_text.should == read_fixture("bible_gateway/bible_gateway.txt")
59
+ end
60
+
61
+ it "is aliased to .to_s" do
62
+ votd.to_s.should == read_fixture("bible_gateway/bible_gateway.txt")
63
+ end
64
+ end
65
+
66
+ describe ".custom_text" do
67
+ it "overrides the default.to_text formatting" do
68
+ text_from_block = votd.custom_text do |votd|
69
+ "#{votd.reference}|#{votd.text}|#{votd.version}"
70
+ end
71
+ desired_output = read_fixture("bible_gateway/bible_gateway_custom.txt")
72
+ text_from_block.should == desired_output
73
+ votd.to_text.should == desired_output
74
+ end
75
+ end
76
+
77
+ end
@@ -20,9 +20,10 @@ describe "Votd::NETBible" do
20
20
  end
21
21
  end
22
22
 
23
- describe ".version" do
23
+ describe ".version / .translation" do
24
24
  it "returns the correct bible version" do
25
- votd.version.should == "NETBible"
25
+ votd.version.should == "NETBible"
26
+ votd.translation.should == "NETBible"
26
27
  end
27
28
  end
28
29
 
@@ -40,7 +41,38 @@ describe "Votd::NETBible" do
40
41
 
41
42
  describe ".to_html" do
42
43
  it "returns a HTML version" do
43
- votd.to_html.should == File.read(fixture("netbible.html"))
44
+ votd.to_html.should == read_fixture("netbible/netbible.html")
44
45
  end
45
46
  end
47
+
48
+ describe ".custom_html" do
49
+ it "overrides the default .to_html formatting" do
50
+ votd.custom_html do |votd|
51
+ "<p>#{votd.reference}|#{votd.text}|#{votd.version}</p>"
52
+ end
53
+ votd.to_html.should == read_fixture("netbible/netbible_custom.html")
54
+ end
55
+ end
56
+
57
+ describe ".to_text" do
58
+ it "returns a text-formatted version" do
59
+ votd.to_text.should == read_fixture("netbible/netbible.txt")
60
+ end
61
+
62
+ it "is aliased to .to_s" do
63
+ votd.to_s.should == read_fixture("netbible/netbible.txt")
64
+ end
65
+ end
66
+
67
+ describe ".custom_text" do
68
+ it "overrides the default.to_text formatting" do
69
+ text_from_block = votd.custom_text do |votd|
70
+ "#{votd.reference}|#{votd.text}|#{votd.version}"
71
+ end
72
+ desired_output = read_fixture("netbible/netbible_custom.txt")
73
+ text_from_block.should == desired_output
74
+ votd.to_text.should == desired_output
75
+ end
76
+ end
77
+
46
78
  end
data/spec/spec_helper.rb CHANGED
@@ -11,12 +11,16 @@ RSpec.configure do |config|
11
11
  File.join(File.dirname(__FILE__), 'fixtures', filename)
12
12
  end
13
13
 
14
+ def read_fixture(filename)
15
+ File.read(fixture(filename))
16
+ end
17
+
14
18
  # Register Bible Gateway URI
15
19
  FakeWeb.register_uri(:get, Votd::BibleGateway::URI,
16
- :body => open(fixture("bible_gateway.rss")))
20
+ :body => open(fixture("bible_gateway/bible_gateway.rss")))
17
21
 
18
22
  # Register NETBible URI
19
23
  FakeWeb.register_uri(:get, Votd::NetBible::URI,
20
- :body => open(fixture("netbible.json")))
24
+ :body => open(fixture("netbible/netbible.json")))
21
25
 
22
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: votd
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -183,11 +183,20 @@ files:
183
183
  - lib/votd/bible_gateway.rb
184
184
  - lib/votd/netbible.rb
185
185
  - lib/votd/version.rb
186
- - spec/fixtures/base.html
187
- - spec/fixtures/bible_gateway.html
188
- - spec/fixtures/bible_gateway.rss
189
- - spec/fixtures/netbible.html
190
- - spec/fixtures/netbible.json
186
+ - spec/fixtures/base/base.html
187
+ - spec/fixtures/base/base.txt
188
+ - spec/fixtures/base/base_custom.html
189
+ - spec/fixtures/base/base_custom.txt
190
+ - spec/fixtures/bible_gateway/bible_gateway.html
191
+ - spec/fixtures/bible_gateway/bible_gateway.rss
192
+ - spec/fixtures/bible_gateway/bible_gateway.txt
193
+ - spec/fixtures/bible_gateway/bible_gateway_custom.html
194
+ - spec/fixtures/bible_gateway/bible_gateway_custom.txt
195
+ - spec/fixtures/netbible/netbible.html
196
+ - spec/fixtures/netbible/netbible.json
197
+ - spec/fixtures/netbible/netbible.txt
198
+ - spec/fixtures/netbible/netbible_custom.html
199
+ - spec/fixtures/netbible/netbible_custom.txt
191
200
  - spec/lib/votd/base_spec.rb
192
201
  - spec/lib/votd/bible_gateway_spec.rb
193
202
  - spec/lib/votd/netbible_spec.rb
@@ -220,11 +229,20 @@ signing_key:
220
229
  specification_version: 3
221
230
  summary: Generate a (Bible) Verse of the Day using various web service wrappers
222
231
  test_files:
223
- - spec/fixtures/base.html
224
- - spec/fixtures/bible_gateway.html
225
- - spec/fixtures/bible_gateway.rss
226
- - spec/fixtures/netbible.html
227
- - spec/fixtures/netbible.json
232
+ - spec/fixtures/base/base.html
233
+ - spec/fixtures/base/base.txt
234
+ - spec/fixtures/base/base_custom.html
235
+ - spec/fixtures/base/base_custom.txt
236
+ - spec/fixtures/bible_gateway/bible_gateway.html
237
+ - spec/fixtures/bible_gateway/bible_gateway.rss
238
+ - spec/fixtures/bible_gateway/bible_gateway.txt
239
+ - spec/fixtures/bible_gateway/bible_gateway_custom.html
240
+ - spec/fixtures/bible_gateway/bible_gateway_custom.txt
241
+ - spec/fixtures/netbible/netbible.html
242
+ - spec/fixtures/netbible/netbible.json
243
+ - spec/fixtures/netbible/netbible.txt
244
+ - spec/fixtures/netbible/netbible_custom.html
245
+ - spec/fixtures/netbible/netbible_custom.txt
228
246
  - spec/lib/votd/base_spec.rb
229
247
  - spec/lib/votd/bible_gateway_spec.rb
230
248
  - spec/lib/votd/netbible_spec.rb
File without changes