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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3c7634c3b142ce5a88d05603a3c1e3511a629e5
4
- data.tar.gz: f8f28a75f465ba76b21fd54afd7c65c75c16b733
3
+ metadata.gz: ff523cf34fbe8fa1e6288d26aa32455e1b9ce9be
4
+ data.tar.gz: 34c6c5386bd9c58f63afb9cf21f4a9688923d130
5
5
  SHA512:
6
- metadata.gz: 8748711f3848e9bb9cfbbf9d2629d30ed43d434c1e9259dfe9b16e0fd47c0fd10606df33070ef97b5e22e5dce114635e5fbe879be344af37cd6da8a7a176d233
7
- data.tar.gz: d27e161322269ea36b1bf6475cde05a1dce20551be6f59311a8777229e70051b40ef576b11ba15c75450a5e0018f2a57cde5690c0aae286cba02dd9da77e4e02
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
+
@@ -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
- class_eval do
18
- define_method(generator_name) do
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
 
@@ -7,10 +7,22 @@ module NoraMark
7
7
  NoraMark::Document.register_generator(generator)
8
8
  end
9
9
 
10
- def load_generator(generator)
11
- module_name = '::NoraMark::#{generator.to_s.capitalize}::Generator'
12
- return const_get(module_name) if const_defined? module_name.to_sym
13
- path = "#{generator.to_s.lowercase}.rb"
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 "noramark/#{generator.to_s.lowercase}"
33
+ require "noramark_#{generator.to_s.downcase}"
22
34
  end
23
- const_defined?(module_name.to_sym) ? const_get(module_name) : nil
35
+ const_get_if_available(module_name)
24
36
  end
25
37
  end
26
38
  end
@@ -1,3 +1,3 @@
1
1
  module NoraMark
2
- VERSION = "0.2beta8"
2
+ VERSION = "0.2beta9"
3
3
  end
@@ -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
+
@@ -0,0 +1,14 @@
1
+ module NoraMark
2
+ module Tester
3
+ class Generator
4
+ def self.name
5
+ :tester
6
+ end
7
+ def initialize(param = {})
8
+ end
9
+ def convert(parsed_result, render_parameter = {})
10
+ 'it is just a test.'
11
+ end
12
+ end
13
+ end
14
+ end
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.2beta8
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