cskit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +8 -0
  3. data/History.txt +3 -0
  4. data/LICENSE +177 -0
  5. data/README.md +246 -0
  6. data/Rakefile +29 -0
  7. data/cskit.gemspec +25 -0
  8. data/lib/cskit/annotated_string.rb +73 -0
  9. data/lib/cskit/annotator.rb +16 -0
  10. data/lib/cskit/formatters/bible/bible_html_formatter.rb +41 -0
  11. data/lib/cskit/formatters/bible/bible_plain_text_formatter.rb +117 -0
  12. data/lib/cskit/formatters/bible.rb +12 -0
  13. data/lib/cskit/formatters/science_health/science_health_html_formatter.rb +32 -0
  14. data/lib/cskit/formatters/science_health/science_health_plain_text_formatter.rb +73 -0
  15. data/lib/cskit/formatters/science_health.rb +12 -0
  16. data/lib/cskit/formatters.rb +19 -0
  17. data/lib/cskit/lesson/lesson.rb +72 -0
  18. data/lib/cskit/lesson/section.rb +26 -0
  19. data/lib/cskit/lesson.rb +10 -0
  20. data/lib/cskit/parsers/bible/bible.rb +1005 -0
  21. data/lib/cskit/parsers/bible/bible.treetop +64 -0
  22. data/lib/cskit/parsers/bible/nodes.rb +153 -0
  23. data/lib/cskit/parsers/bible/objects.rb +81 -0
  24. data/lib/cskit/parsers/science_health/nodes.rb +82 -0
  25. data/lib/cskit/parsers/science_health/objects.rb +47 -0
  26. data/lib/cskit/parsers/science_health/science_health.rb +607 -0
  27. data/lib/cskit/parsers/science_health/science_health.treetop +44 -0
  28. data/lib/cskit/parsers.rb +8 -0
  29. data/lib/cskit/readers/bible_reader.rb +58 -0
  30. data/lib/cskit/readers/reading.rb +54 -0
  31. data/lib/cskit/readers/science_health_reader.rb +97 -0
  32. data/lib/cskit/readers.rb +9 -0
  33. data/lib/cskit/resources/volumes/bible.rb +45 -0
  34. data/lib/cskit/resources/volumes/science_health.rb +49 -0
  35. data/lib/cskit/resources/volumes.rb +8 -0
  36. data/lib/cskit/version.rb +5 -0
  37. data/lib/cskit/volume.rb +33 -0
  38. data/lib/cskit.rb +73 -0
  39. metadata +122 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjI2YTAyZWQ5ZDVlMTQ0OGVmMDFmODEzMjAxNjExMjJlODMyNjk3MA==
5
+ data.tar.gz: !binary |-
6
+ OTExOGU2MjJjNTUyZWVkMDVlMzEzNGIyMjMwZGJkODYxOTRmYjIxNQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Nzc4MDcyZWE1ZWU5ODg4MTJlNzJhYjU5NmQ2MTYwMWI4YTVlM2RiMjZmYTY5
10
+ MmU5YTFhNjM5NzM4YTYxNWRiNDk5NmIxNWNhMzU4N2JmYzUxMGQxYTZlYjE2
11
+ Mjc4MDhkZWUzODI5ZmI4N2Q1ZTk2NzdiNWUyNTlhNDJlOGJkN2E=
12
+ data.tar.gz: !binary |-
13
+ YzdmOGI5YmFkZjc0OTYzYmVmODJlNzEwYzI5MTkwYTdmYjQ4N2I0OGQ2NTI5
14
+ YTNkY2JjZDEzYjNjZjEwZGNiMzMyZDllMmI5NzQ4MTI2YTBjNjAzYWFmODg5
15
+ NzYyZWYwNWY5MjNhNDZjYmE1MjRlZDFjMjU4ZDQ5MThkOWNhNjU=
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "pry"
7
+ gem "pry-nav"
8
+ end
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 1.0.0
2
+
3
+ * Birthday!
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
data/README.md ADDED
@@ -0,0 +1,246 @@
1
+ ## cskit-rb
2
+
3
+ CSKit is a citation parsing and retrieval toolkit for various Christian Science textual resources. It features a pluggable architecture, meaning all the textual data is stored in separate gems.
4
+
5
+ ## Available Textual Resources
6
+
7
+ 1. King James Bible ([cskit-biblekjv-rb](https://github.com/camertron/cskit-biblekjv-rb))
8
+ 2. Science and Health with Key to the Scriptures ([cskit-shkts-rb](https://github.com/camertron/cskit-shkts-rb))
9
+ 3. Christian Science Hymnal ([cskit-hymnal-rb](https://github.com/camertron/cskit-hymnal-rb))
10
+
11
+ ## Installation
12
+
13
+ `gem install cskit`, `gem install cskit-shkts`, etc
14
+
15
+ or, with bundler:
16
+
17
+ ```ruby
18
+ gem 'cskit-rb', '~> 1.0.0'
19
+ gem 'cskit-shkts-rb', '~> 1.0.0'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ # base CSKit library
26
+ require 'cskit'
27
+
28
+ # will make data available from cskit-shkts-rb
29
+ require 'cskit/science_health'
30
+ ```
31
+
32
+ ### Basics
33
+
34
+ Requiring one of the textual resource gems (eg. `require 'cskit/science_health'`) will make the resource available as a `Volume`. `Volume`s provide access to a single textual resource and expose, among other things, a citation parser and a text reader. Use each `Volume`'s `parse_citation` and `readings_for` methods to parse citations and retrieve text. You can learn more about these specific components below.
35
+
36
+ You can ask CSKit which textual resources are currently available via the `available_volumes` method:
37
+
38
+ ```ruby
39
+ require 'cskit/science_health'
40
+ require 'cskit/bible/kjv'
41
+
42
+ CSKit.available_volumes # { :science_health => ..., :bible_kjv => ... }
43
+ CSKit.volume_available?(:science_health) # true
44
+ CSKit.volume_available?(:blarg) # false
45
+ ```
46
+
47
+ Get volume objects directly by using the `get_volume` method. Note that CSKit can find volumes by their type as well as by their name. These two statements are equivalent because on failing to find `:bible` by name, CSKit will fallback to the last registered volume of the type "bible".
48
+
49
+ ```ruby
50
+ CSKit.get_volume(:bible_kjv)
51
+ CSKit.get_volume(:bible)
52
+ ```
53
+
54
+ #### Definitions
55
+
56
+ CSKit uses vocabulary that helps consistently describe the objects in the system. Here are a few definitions that may be helpful to you as you spelunk this documentation and the source code:
57
+
58
+ 1. **Volume**: A textual resource. This should probably have been named "book", but "book of the bible" introduces ambiguity, so "volume" it is.
59
+ 2. **Citation**: References text in a volume. Parsers generate citation objects, and citation objects are passed to readers.
60
+ 3. **Parser**: Converts a citation string into a citation object so it can be used to retrieve text.
61
+ 4. **Reader**: An interface for retrieving text from a volume.
62
+ 5. **Lesson**: A collection of citations divided into sections. Each section contains a number of citations and their corresponding volumes. Analogous to the weekly Christian Science Bible Lesson.
63
+ 6. **Section**: A group of citations, possibly refrencing multiple volumes.
64
+ 7. **Formatter**: Logic for rendering readings.
65
+ 8. **Reading**: Text for a single citation. Made up of multiple texts.
66
+ 9. **Text**: A single unit of text, eg. line, verse, etc.
67
+
68
+ ### Lessons
69
+
70
+ CSKit features a `Lesson` class that is capable of reading in a JSON file and assembling text from a series of volumes for a group of citations (i.e. the weekly Bible Lesson):
71
+
72
+ ```ruby
73
+ include CSKit::Lesson
74
+ lesson = Lesson.from_file("/path/to/love.json")
75
+ ```
76
+
77
+ You can iterate over the readings in each section using the `each_reading`, `each_formatted_reading`, and `each_formatted_section` methods. Here are examples for each:
78
+
79
+ `each_reading` iterates over each reading in each section for the given volumes. Formatting the text in each reading is up to you - this function returns the raw text only.
80
+
81
+ ```ruby
82
+ lesson.each_reading(:bible, :science_health) do |section, citation, volume, readings|
83
+ if volume == :bible
84
+ readings.each do |reading|
85
+ puts reading.texts.join(" ")
86
+ end
87
+ end
88
+ end
89
+ ```
90
+
91
+ `each_formatted_reading` iterates over each section, handing you the formatted text for each group of readings. More on formatters later.
92
+
93
+ ```ruby
94
+ include CSKit::Formatters::ScienceHealth
95
+ include CSKit::Formatters::Bible
96
+
97
+ formatters = {
98
+ :science_health => ScienceHealthPlainTextFormatter.new
99
+ :bible => BiblePlainTextFormatter.new
100
+ }
101
+
102
+ lesson.each_formatted_reading(formatters) do |section, citation, volume, text|
103
+ if volume == :bible
104
+ puts "Bible: #{text}"
105
+ end
106
+ end
107
+ ```
108
+
109
+ `each_formatted_section` is similar to `each_formatted_reading` but hands you a hash of formatted reading groups by volume instead of yielding each reading group one at a time.
110
+
111
+ ```ruby
112
+ lesson.each_formatted_section(formatters) do |section, text_by_volume|
113
+ puts text_by_volume[:bible]
114
+ end
115
+ ```
116
+
117
+ #### File Format
118
+
119
+ Here's an example JSON file for a lesson. Note that each volume name (eg. "bible", "science_health") must match an available volume (see above).
120
+
121
+ ```
122
+ [
123
+ {
124
+ "section": "1",
125
+ "readings": {
126
+ "bible": [
127
+ "Gen. 12:1-3 the (to :)",
128
+ "Gen. 17:1, 2, 5",
129
+ "Gen. 22:17 in (to 1st ;), 18",
130
+ "Ps. 91:14"
131
+ ],
132
+ "science_health": [
133
+ "275:12-17",
134
+ "579:10-14",
135
+ "507:6-7",
136
+ "140:8-12",
137
+ "264:15"
138
+ ]
139
+ }
140
+ },
141
+
142
+ { ... }
143
+ ]
144
+ ```
145
+
146
+ ### Parsing Citations
147
+
148
+ CSKit contains a number of parsers that can transform a citation string into a citation object. For example, the `BibleParser` can read and interpret "Gen. 12:1-3 the (to :)" like so:
149
+
150
+ ```ruby
151
+ include CSKit::Parsers
152
+
153
+ parser = BibleParser.new
154
+ citation = parser.parse("Gen. 12:1-3 the (to :)").to_object
155
+
156
+ citation.book # "Gen."
157
+ citation.chapter_list # [#<Chapter .. >, #<Chapter .. >, ...]
158
+ citation.chapter_list.first.tap do |chapter|
159
+ chapter.chapter_number # 12
160
+ chapter.verse_list # [#<Verse ..>, ...]
161
+ chapter.verse_list.first.tap do |verse|
162
+ verse.start # 1
163
+ verse.finish # 3
164
+ verse.starter.fragment # "and in"
165
+ verse.terminator.fragment # ":"
166
+ verse.terminator.cardinality # 1
167
+ end
168
+ end
169
+ ```
170
+
171
+ In addition, each volume provides a thin wrapper around the appropriate parser object, so you don't have to create one manually:
172
+
173
+ ```ruby
174
+ volume = CSKit.get_volume(:bible)
175
+ volume.parse_citation("Gen. 12:1-3 the (to :)") # returns a citation object
176
+ ```
177
+
178
+ ### Retrieving Citations
179
+
180
+ Once you have a citation object, you'll likely want to fetch text - the responsibility of a reader. Readers take in citations and return an array of `Reading` objects:
181
+
182
+ ```ruby
183
+ include CSKit::Readers
184
+
185
+ reader = BibleReader.new(volume)
186
+ reader.get_book("Genesis") # #<Book .. >
187
+ reader.get_chapter(12, "Genesis"), # #<Chapter .. >
188
+
189
+ reader.readings_for(citation) # [#<Reading .. >, ... ]
190
+ ```
191
+
192
+ In addition, each volume provides a thin wrapper around the appropriate reader object, so you don't have to create one manually:
193
+
194
+ ```ruby
195
+ volume.readings_for(citation) # [#<Reading .. >, ... ]
196
+ ```
197
+
198
+ ### Formatting Text
199
+
200
+ Now that you have text in the form of `Reading` objects, you might want to format it for display - the responsibility of a formatter. Currently, CSKit contains two formatters, one for the Bible and another for Science and Health. Both of these format `Reading` objects as plain text. If you'd like to apply a different style of formatting (eg. HTML), you'll need to create your own class.
201
+
202
+ Here's a formatting example for the Bible citation we've been using:
203
+
204
+ ```ruby
205
+ include CSKit::Formatters::Bible
206
+
207
+ readings = reader.readings_for(citation)
208
+
209
+ # these options are actually the defaults, shown here for demonstration purposes
210
+ formatter = BiblePlainTextFormatter.new(
211
+ :include_verse_number => true,
212
+ :separator => " "
213
+ )
214
+
215
+ formatter.format_readings(readings)
216
+ ```
217
+
218
+ The formatted output (carriage returns added manually for Github display reasons):
219
+
220
+ ```
221
+ 1 ...the LORD had said unto Abram, Get thee out of thy country, and from thy kindred,
222
+ and from thy father's house, unto a land that I will shew thee: 2 And I will make of thee
223
+ a great nation, and I will bless thee, and make thy name great; and thou shalt be a
224
+ blessing: 3 And I will bless them that bless thee, and curse him that curseth thee:
225
+ ```
226
+
227
+ For Science and Health, use the `ScienceHealthPlainTextFormatter` class.
228
+
229
+ ## Requirements
230
+
231
+ CSKit needs to parse JSON, so it depends on the json gem.
232
+
233
+ ## Running Tests
234
+
235
+ `bundle exec rake` will run the test suite, although at the current time there are no tests :(
236
+
237
+ ## Authors
238
+
239
+ * Cameron C. Dutro: http://github.com/camertron
240
+
241
+ ## Links
242
+ * Project Gutenberg: [http://gutenberg.org/](http://gutenberg.org/)
243
+
244
+ ## License
245
+
246
+ Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
7
+
8
+ require 'bundler'
9
+ require 'digest'
10
+
11
+ require 'rubygems/package_task'
12
+
13
+ Bundler::GemHelper.install_tasks
14
+
15
+ namespace :parsers do
16
+ task :compile do
17
+ base_path = File.dirname(__FILE__)
18
+ parser_paths = [
19
+ "lib/cskit/parsers/bible/bible.treetop",
20
+ "lib/cskit/parsers/science_health/science_health.treetop"
21
+ ]
22
+
23
+ parser_paths.each do |parser_path|
24
+ full_path = File.join(base_path, parser_path)
25
+ puts "Compiling #{full_path}"
26
+ `bundle exec tt #{full_path}`
27
+ end
28
+ end
29
+ end
data/cskit.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
4
+ require 'cskit/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cskit"
8
+ s.version = ::CSKit::VERSION
9
+ s.authors = ["Cameron Dutro"]
10
+ s.email = ["camertron@gmail.com"]
11
+ s.homepage = "http://github.com/camertron"
12
+
13
+ s.description = s.summary = "Christian Science citation library for Ruby."
14
+
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+
18
+ s.add_dependency 'json'
19
+ s.add_dependency 'treetop'
20
+
21
+ s.add_development_dependency 'rake'
22
+
23
+ s.require_path = 'lib'
24
+ s.files = Dir["{lib,spec,resources}/**/*", "Gemfile", "History.txt", "LICENSE", "README.md", "Rakefile", "cskit.gemspec"]
25
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ class AnnotatedString
5
+
6
+ attr_reader :string
7
+ attr_reader :annotations
8
+
9
+ def initialize(string, annotations = [])
10
+ @string = string
11
+ @annotations = annotations
12
+ end
13
+
14
+ def add_annotation(annotation)
15
+ annotations << annotation
16
+ end
17
+
18
+ def render
19
+ each_chunk.map do |text, annotation|
20
+ if annotation
21
+ yield text, annotation
22
+ else
23
+ text
24
+ end
25
+ end.join
26
+ end
27
+
28
+ def delete(pos, length)
29
+ new_length = string.length - length
30
+
31
+ annotations.reject! do |annotation|
32
+ reject = annotation.start >= new_length || annotation.finish >= new_length
33
+
34
+ if annotation.start >= pos
35
+ annotation.start -= length
36
+ annotation.finish -= length
37
+ end
38
+
39
+ reject || (annotation.start < 0 || annotation.finish < 0)
40
+ end
41
+
42
+ @string = @string[0...pos] + @string[(pos + length)..-1]
43
+ end
44
+
45
+ private
46
+
47
+ def each_chunk(&block)
48
+ enum = Enumerator.new do |yielder|
49
+ last = 0
50
+ sorted_annotations.each do |annotation|
51
+ starter = string[last...annotation.start]
52
+ yielder.yield(starter, nil) unless starter.empty?
53
+
54
+ middle = string[annotation.start..annotation.finish]
55
+ yielder.yield(middle, annotation)
56
+ last = annotation.finish + 1
57
+ end
58
+
59
+ terminator = string[last..-1]
60
+ yielder.yield(terminator, nil) unless terminator.empty?
61
+ end
62
+
63
+ block_given? ? enum.each(&block) : enum
64
+ end
65
+
66
+ def sorted_annotations
67
+ annotations.sort do |a, b|
68
+ a.start <=> b.start
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ class Annotator
5
+
6
+ attr_reader :config
7
+
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+
12
+ end
13
+
14
+ Annotation = Struct.new(:start, :finish, :data)
15
+
16
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ module CSKit
4
+ module Formatters
5
+ module Bible
6
+ class BibleHtmlFormatter < BiblePlainTextFormatter
7
+
8
+ protected
9
+
10
+ def format_verse_texts(texts, verse)
11
+ texts.each_with_index.map do |text, index|
12
+ if index == 0
13
+ pos = starter_position(text, verse.starter)
14
+ text = format_starter(text, pos)
15
+ end
16
+
17
+ if index == texts.size - 1
18
+ pos = terminator_position(text, verse.terminator)
19
+ text = format_terminator(text, pos)
20
+ end
21
+
22
+ verse_number = verse.start + index
23
+ verse_number = wrap_verse_number(verse_number)
24
+ text = wrap_text(text)
25
+
26
+ include_verse_number? ? "#{verse_number} #{text}" : text
27
+ end
28
+ end
29
+
30
+ def wrap_text(text)
31
+ "<span class='cskit-verse-text>#{text}</span>"
32
+ end
33
+
34
+ def wrap_verse_number(verse_number)
35
+ "<span class='cskit-verse-number'>#{verse_number}</span>"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end