smarky 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 498ca46d8878825f6416da7310e082abbbac9d8b
4
- data.tar.gz: fa44aac8e0ec3ce1abc7ea3cfafbfd4a9249a467
3
+ metadata.gz: d899ab9c2c49e0e1ef563a405a33f34ceea8f679
4
+ data.tar.gz: 517a6dcf52a81fdc4bdd56cc4f49150fe512c872
5
5
  SHA512:
6
- metadata.gz: 5954494b1daa014a2d97df8f96cd279d1fbe021d12179f76c9576928a59b82f1c6ac3814660a0e3a496bac112f098dcee593cbc32607a347362032c6fcad63f0
7
- data.tar.gz: cd208436b638fff4d9689debc1c4c66856fa1fa82a139440acd56e6276169ffd512554193c7ef4b6fe993368bc81398905fb6831b2559bc3fd430eb05d7f2ece
6
+ metadata.gz: 23932ef26b235379ba126df3e93e7b20cae2769cc1916a1472b7a83f358a158c5445ecb83bd05c37b23a5c0e7c4f37147ce07095944e4aa36676605fa47bd2ee
7
+ data.tar.gz: 19c27661e90205aa476c0ffa889e833e2628a7f471466c05d9d18c0b3e859a32a133811669fbf6b09e9b2c2b84d85330fbf94767b74e6ce6f12a07889a674813
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  Gemfile.lock
2
+ *.gem
data/CHANGES.md ADDED
@@ -0,0 +1,9 @@
1
+ 0.0.2
2
+ -----
3
+
4
+ * added IDs to generated `<section>` tags
5
+
6
+ 0.0.1
7
+ -----
8
+
9
+ * first version
data/README.md CHANGED
@@ -58,6 +58,9 @@ article.sections
58
58
 
59
59
  article.to_html
60
60
  # => the structured HTML
61
+
62
+ article.inner_html
63
+ # => if you want to inject the HTML into an existing container
61
64
  ```
62
65
 
63
66
  Choosing a Markdown renderer
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
- new_section = Element.new('section', heading[0])
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
@@ -29,6 +29,14 @@ module Smarky
29
29
  @node.name
30
30
  end
31
31
 
32
+ def attributes
33
+ @node.attributes
34
+ end
35
+
36
+ def []=(attribute, value)
37
+ @node[attribute] = value
38
+ end
39
+
32
40
  def content
33
41
  @node.content
34
42
  end
@@ -1,3 +1,3 @@
1
1
  module Smarky
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-03 00:00:00.000000000 Z
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