cmless 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmless.rb +13 -3
  3. metadata +9 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df8fed832f07c5ef9e406e7f3c590953077593c2
4
- data.tar.gz: a6cbc326451f8f7a98e1354cf4e27a2db48f240d
3
+ metadata.gz: 71291ab765119f91a569df33d1bcda76dc712b24
4
+ data.tar.gz: 486cbed8c5a213dc9ce20bc77c6adc907b918b74
5
5
  SHA512:
6
- metadata.gz: 46458a0196b24c28bfd50d92e94c3ebc4f9c008d582b007941c5aba3b0e3d4aa75c2c441333dc7d95549fd04fa6bd671b194c87e2407c13d27113df688827517
7
- data.tar.gz: a77ac6ff4f1b7182ce9ca70f957f6acde6012c7e2fda42f1cf5aeb43c1834d946b691a42334c3836dcfbdd38ed8efbe9c9b6d1a6d9729f5bd6c87307166c727e
6
+ metadata.gz: bd64091fd7602fe18afc0b338904ba35bbf34af932bbc5b505842bc4048c380da7206eda5b0eed1934a215d06cd752248d3d9e6821284480e91ec9bb2ba598e5
7
+ data.tar.gz: 291078301bbfec1daff3847454cf111bee3d091fdf5a32f927d6506670b9eb45497a8fcb1ded5b8a814ab6a7c4bfbf831a20cf2276fc85da6f020704860aab66
@@ -14,6 +14,9 @@ class Cmless
14
14
  attr_reader :title_html
15
15
  attr_reader :toc_html
16
16
 
17
+ class Cmless::Error < StandardError
18
+ end
19
+
17
20
  private
18
21
 
19
22
  # You should use find_by_path rather than creating your own instances.
@@ -55,7 +58,7 @@ class Cmless
55
58
  value ||= if parent # Look at parent if missing on self.
56
59
  parent.send(method)
57
60
  else
58
- fail(IndexError.new("Can't find '#{method}'"))
61
+ fail(StandardError.new("Can't find '#{method}'"))
59
62
  end
60
63
  instance_variable_set("@#{method}", value)
61
64
  end
@@ -114,7 +117,7 @@ class Cmless
114
117
 
115
118
  def find_by_path(path)
116
119
  objects_by_path[path] ||
117
- fail(IndexError.new(
120
+ fail(Cmless::Error.new(
118
121
  "'#{path}' is not a valid path under '#{self::ROOT}'; " \
119
122
  "Expected one of #{objects_by_path.keys}"))
120
123
  end
@@ -146,7 +149,14 @@ class Cmless
146
149
 
147
150
  def extract_html(doc, title)
148
151
  following_siblings = []
149
- doc.xpath("//h2[text()='#{title}']").first.tap do |header|
152
+ # UGLY:
153
+ # - title coming in is based on method name,
154
+ # so it will only be [a-z0-9_].
155
+ # - Nokogiri only has XPath 1.0, so no regex replacements,
156
+ # so we can't list every possible bad character.
157
+ # - XPath itself does not have a syntax for escaping in string literals,
158
+ # so we concat.
159
+ doc.xpath("//h2[translate(text(),concat('~!@#\{$%^&*()_+`-=\}-\";:<>,.?/|\[]',\"'\"),'')='#{title}']").first.tap do |header|
150
160
  return nil unless header
151
161
  while header.next_element && !header.next_element.name.match(/h2/)
152
162
  following_siblings.push(header.next_element.remove)
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck McCallum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  description: |
@@ -56,19 +56,18 @@ require_paths:
56
56
  - lib
57
57
  required_ruby_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.2.3
69
+ rubygems_version: 2.4.6
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: CMS, but less
73
73
  test_files: []
74
- has_rdoc: