smarky 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGES.md +9 -0
- data/README.md +3 -0
- data/lib/smarky.rb +4 -1
- data/lib/smarky/element.rb +8 -0
- data/lib/smarky/version.rb +1 -1
- data/spec/smarky_spec.rb +9 -0
- data/spec/spec_helper.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d899ab9c2c49e0e1ef563a405a33f34ceea8f679
|
4
|
+
data.tar.gz: 517a6dcf52a81fdc4bdd56cc4f49150fe512c872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23932ef26b235379ba126df3e93e7b20cae2769cc1916a1472b7a83f358a158c5445ecb83bd05c37b23a5c0e7c4f37147ce07095944e4aa36676605fa47bd2ee
|
7
|
+
data.tar.gz: 19c27661e90205aa476c0ffa889e833e2628a7f471466c05d9d18c0b3e859a32a133811669fbf6b09e9b2c2b84d85330fbf94767b74e6ce6f12a07889a674813
|
data/.gitignore
CHANGED
data/CHANGES.md
ADDED
data/README.md
CHANGED
data/lib/smarky.rb
CHANGED
@@ -13,8 +13,11 @@ module Smarky
|
|
13
13
|
|
14
14
|
fragment.children.each do |node|
|
15
15
|
if (heading = node.name.match(/^h(\d)$/i))
|
16
|
-
|
16
|
+
title = node.content
|
17
|
+
|
18
|
+
new_section = Element.new('section', title)
|
17
19
|
new_section.add_child(Element.new(node))
|
20
|
+
new_section['id'] = title.downcase.gsub(/[^0-9A-Z]/i, '-')
|
18
21
|
|
19
22
|
level = heading[1].to_i
|
20
23
|
if current_level.nil? || level > current_level
|
data/lib/smarky/element.rb
CHANGED
data/lib/smarky/version.rb
CHANGED
data/spec/smarky_spec.rb
CHANGED
@@ -77,6 +77,15 @@ describe Smarky do
|
|
77
77
|
]
|
78
78
|
end
|
79
79
|
|
80
|
+
it 'attaches IDs to HTML sections' do
|
81
|
+
input <<-EOMARKDOWN
|
82
|
+
Section 1
|
83
|
+
=========
|
84
|
+
EOMARKDOWN
|
85
|
+
|
86
|
+
verify_result '<article><section id="section-1"><h1>Section 1</h1></section></article>'
|
87
|
+
end
|
88
|
+
|
80
89
|
it 'renders nested sections for heading elements with descending rank' do
|
81
90
|
input <<-EOMARKDOWN
|
82
91
|
Section 1
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,10 @@ end
|
|
9
9
|
def node_to_array(node)
|
10
10
|
array = [node.name.to_sym]
|
11
11
|
|
12
|
+
# if node.attributes.any?
|
13
|
+
# array << attribute_hash(node.attributes)
|
14
|
+
# end
|
15
|
+
|
12
16
|
if node.children.empty?
|
13
17
|
array << node.content
|
14
18
|
|
@@ -24,6 +28,13 @@ def node_to_array(node)
|
|
24
28
|
array
|
25
29
|
end
|
26
30
|
|
31
|
+
def attribute_hash(attributes)
|
32
|
+
attributes.inject({}) do |hash, (name, attribute)|
|
33
|
+
hash[name.to_sym] = attribute.content
|
34
|
+
hash
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
27
38
|
RSpec.configure do |config|
|
28
39
|
config.before :each do
|
29
40
|
@input = ''
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smarky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Tao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -130,6 +130,7 @@ extensions: []
|
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
132
|
- .gitignore
|
133
|
+
- CHANGES.md
|
133
134
|
- Gemfile
|
134
135
|
- LICENSE.txt
|
135
136
|
- README.md
|