nora_mark 0.2beta8 → 0.2beta9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/nora_mark/document.rb +19 -4
- data/lib/nora_mark/extensions.rb +18 -6
- data/lib/nora_mark/version.rb +1 -1
- data/spec/extensions_spec.rb +31 -0
- data/spec/fixtures/test-plugins/noramark_tester.rb +14 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff523cf34fbe8fa1e6288d26aa32455e1b9ce9be
|
4
|
+
data.tar.gz: 34c6c5386bd9c58f63afb9cf21f4a9688923d130
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e087b116de63c76b1a14c62fc85d07bd6aff7a06d1e2aa21017dae5a42f1273d3fbab321d0e931f780bbe38bf2224e91527a7cf52fd1e7e2ad3df5a108d450e4
|
7
|
+
data.tar.gz: c719ce76365568d89719f6554c5039f470c8b0fcd77b4d1eb4d73f08f617ee6cab6f468789c7572837e242364fe0e62faddee12ab6749fad9355f7f1b87511ee
|
data/README.md
CHANGED
@@ -362,3 +362,16 @@ https://github.com/skoji/noramark/blob/master/emacs-mode/noramark-mode.el
|
|
362
362
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
363
363
|
4. Push to the branch (`git push origin my-new-feature`)
|
364
364
|
5. Create new Pull Request
|
365
|
+
|
366
|
+
## Related Project
|
367
|
+
|
368
|
+
### NoraMark HTMLBook
|
369
|
+
|
370
|
+
https://github.com/skoji/nora_mark_htmlbook
|
371
|
+
HTMLBook generator plugin
|
372
|
+
|
373
|
+
### NoraMark.js
|
374
|
+
|
375
|
+
https://github.com/skoji/noramark.js
|
376
|
+
JavaScript port of NoraMark.
|
377
|
+
|
data/lib/nora_mark/document.rb
CHANGED
@@ -14,13 +14,24 @@ module NoraMark
|
|
14
14
|
generator_name = generator.name
|
15
15
|
@generators[generator_name] = generator
|
16
16
|
generator.activate self if generator.respond_to? :activate
|
17
|
-
|
18
|
-
|
19
|
-
generate(generator_name)
|
20
|
-
end
|
17
|
+
define_method(generator_name) do
|
18
|
+
generate(generator_name)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
22
|
+
def self.unregister_generator(generator)
|
23
|
+
@generators ||= {}
|
24
|
+
if generator.is_a? Symbol or generator.is_a? String
|
25
|
+
generator_name = generator.to_sym
|
26
|
+
else
|
27
|
+
generator_name = generator.name
|
28
|
+
end
|
29
|
+
|
30
|
+
@generators.delete generator_name
|
31
|
+
generator.deactivate self if generator.respond_to? :deactivate
|
32
|
+
remove_method generator_name
|
33
|
+
end
|
34
|
+
|
24
35
|
register_generator(::NoraMark::Html::Generator)
|
25
36
|
|
26
37
|
def self.parse(string_or_io, param = {})
|
@@ -47,6 +58,10 @@ module NoraMark
|
|
47
58
|
page_no
|
48
59
|
end
|
49
60
|
end
|
61
|
+
frontmatter = instance.root.find_node :type => :Frontmatter
|
62
|
+
if (frontmatter&& frontmatter.yaml['generator'])
|
63
|
+
NoraMark::Extensions.register_generator(frontmatter.yaml['generator'].to_sym)
|
64
|
+
end
|
50
65
|
instance
|
51
66
|
end
|
52
67
|
|
data/lib/nora_mark/extensions.rb
CHANGED
@@ -7,10 +7,22 @@ module NoraMark
|
|
7
7
|
NoraMark::Document.register_generator(generator)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def self.unregister_generator(generator)
|
11
|
+
NoraMark::Document.unregister_generator(generator)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.const_get_if_available(name)
|
15
|
+
name.split(/::/).inject(Object){|o,c|
|
16
|
+
o.const_get(c) if !o.nil? and o.const_defined? c
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def self.load_generator(generator)
|
22
|
+
module_name = "NoraMark::#{generator.to_s.capitalize}::Generator"
|
23
|
+
generator_module = const_get_if_available(module_name)
|
24
|
+
return generator_module unless generator_module.nil?
|
25
|
+
path = "#{generator.to_s.downcase}.rb"
|
14
26
|
current_dir_path = File.expand_path(File.join('.', '.noramark-plugins', path))
|
15
27
|
home_dir_path = File.expand_path(File.join(ENV['HOME'], '.noramark-plugins', path))
|
16
28
|
if File.exist? current_dir_path
|
@@ -18,9 +30,9 @@ module NoraMark
|
|
18
30
|
elsif File.exist? home_dir_path
|
19
31
|
require home_dir_path
|
20
32
|
else
|
21
|
-
require "
|
33
|
+
require "noramark_#{generator.to_s.downcase}"
|
22
34
|
end
|
23
|
-
|
35
|
+
const_get_if_available(module_name)
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|
data/lib/nora_mark/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/nora_mark'
|
4
|
+
require 'nokogiri'
|
5
|
+
require File.dirname(__FILE__) + '/nokogiri_test_helper.rb'
|
6
|
+
|
7
|
+
describe NoraMark::Extensions do
|
8
|
+
describe "register generator in the path" do
|
9
|
+
before(:each) do
|
10
|
+
if NoraMark.const_defined? :Tester
|
11
|
+
NoraMark::Extensions.unregister_generator(:tester)
|
12
|
+
end
|
13
|
+
@test_plugin_dir = File.dirname(__FILE__) + '/fixtures/test-plugins'
|
14
|
+
$:.unshift @test_plugin_dir
|
15
|
+
end
|
16
|
+
it 'load generator from path' do
|
17
|
+
NoraMark::Extensions.register_generator(:tester)
|
18
|
+
nora = NoraMark::Document.parse('text')
|
19
|
+
expect(nora.tester).to eq 'it is just a test.'
|
20
|
+
end
|
21
|
+
it 'load generator from path using frontmatter' do
|
22
|
+
nora = NoraMark::Document.parse("---\ngenerator: tester\n---\ntext")
|
23
|
+
expect(nora.tester).to eq 'it is just a test.'
|
24
|
+
end
|
25
|
+
after(:each) do
|
26
|
+
$:.delete @test_plugin_dir
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nora_mark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2beta9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KOJIMA Satoshi
|
@@ -201,6 +201,8 @@ files:
|
|
201
201
|
- spec/epub30-schemas/package-30.nvdl
|
202
202
|
- spec/epub30-schemas/package-30.rnc
|
203
203
|
- spec/epub30-schemas/package-30.sch
|
204
|
+
- spec/extensions_spec.rb
|
205
|
+
- spec/fixtures/test-plugins/noramark_tester.rb
|
204
206
|
- spec/jing-20091111/bin/jing.jar
|
205
207
|
- spec/node_spec.rb
|
206
208
|
- spec/nokogiri_test_helper.rb
|
@@ -309,6 +311,8 @@ test_files:
|
|
309
311
|
- spec/epub30-schemas/package-30.nvdl
|
310
312
|
- spec/epub30-schemas/package-30.rnc
|
311
313
|
- spec/epub30-schemas/package-30.sch
|
314
|
+
- spec/extensions_spec.rb
|
315
|
+
- spec/fixtures/test-plugins/noramark_tester.rb
|
312
316
|
- spec/jing-20091111/bin/jing.jar
|
313
317
|
- spec/node_spec.rb
|
314
318
|
- spec/nokogiri_test_helper.rb
|