nora_mark 0.2beta14 → 0.2beta15

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: 76d472396b1e19fe29839504931e2a0bf98232c9
4
- data.tar.gz: de110cb90daac76340084bec401ac96178586911
3
+ metadata.gz: cab3cab407b40a37ddb78f770011aabd71768727
4
+ data.tar.gz: 88374067b24427c73c945f0be3fc5654875779f8
5
5
  SHA512:
6
- metadata.gz: c763fb0bdb6865ae5eba947996575f393ebad661b7911f6995e24b66d4141d7ef77845e18120fd45849cf3728c8e6b635716625ef4a76402efcb1b9194bd4996
7
- data.tar.gz: b398c5108846f929f5e963ddcd0d627cc7d300d3c6da03a4d1dcbcd1b99433d4fb3f4c8694ffb56d999fe0ae7ce5893ced967f1a2f032808d9bda37a78c72d57
6
+ metadata.gz: e2d49d88eb73c4d933be68140e0cd6dd0df0336aad343e6cd2dfb32ff5c03e18db38df803c4c4833d5608a57ee891f897c6f41b66997c26253c9a9ce6f4bd25d
7
+ data.tar.gz: e61233e4d76f037e19e786341f31faefed03a36cc6c0b0b8a8a85529b175ce96fc0028cae3e38517f64f9f32516ad1adaf65ad626451c48b9242e084a057d836
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # NoraMark
2
+
3
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/skoji/noramark?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
4
  [<img src="https://secure.travis-ci.org/skoji/noramark.png" />](http://travis-ci.org/skoji/noramark) [![Coverage Status](https://coveralls.io/repos/skoji/noramark/badge.png?branch=master)](https://coveralls.io/r/skoji/noramark?branch=master)
3
5
  [![Dependency Status](https://gemnasium.com/skoji/noramark.png)](https://gemnasium.com/skoji/noramark)
4
6
  [![Gem Version](https://badge.fury.io/rb/nora_mark.png)](http://badge.fury.io/rb/nora_mark)
@@ -3,6 +3,7 @@ module NoraMark
3
3
  class Context
4
4
  attr_accessor :title, :head_inserters, :lang, :stylesheets, :enable_pgroup, :render_parameter, :namespaces, :metas
5
5
  def initialize(param = {})
6
+ @default_param = param
6
7
  @head_inserters = []
7
8
  @lang = param[:lang] || 'en'
8
9
  @title = param[:title] || 'NoraMark generated document'
@@ -10,8 +11,8 @@ module NoraMark
10
11
  @enable_pgroup = param[:enable_pgroup] || true
11
12
  self.paragraph_style= param[:paragraph_style]
12
13
  @pages = Pages.new(param[:sequence_format])
14
+ @metas = param[:metas] || []
13
15
  @namespaces = {}
14
- @metas = []
15
16
  @render_parameter = {}
16
17
  head_inserter do
17
18
  ret = ""
@@ -68,7 +69,7 @@ module NoraMark
68
69
  page = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
69
70
  page << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
70
71
  page << @namespaces.map do |k,v|
71
- "xmlns:#{k}=\"#{v}\""
72
+ " xmlns:#{k}=\"#{v}\""
72
73
  end.join(' ')
73
74
  page << " lang=\"#{@lang}\" xml:lang=\"#{@lang}\">\n"
74
75
  page << "<head>\n"
@@ -88,6 +89,26 @@ module NoraMark
88
89
  page << "</html>\n"
89
90
  page.freeze
90
91
  end
92
+ restore_metas
93
+ end
94
+
95
+ # save metadata written with Frontmatter Writer
96
+ def save_metas
97
+ @default_param[:styleheets] ||= @stylesheets if !@stylesheets.nil? && @stylesheets.size > 0
98
+ @default_param[:title] ||= @title
99
+ @default_param[:lang] ||= @lang
100
+ @default_param[:paragraph_style] ||= @paragraph_style
101
+ @default_param[:namespaces] ||= @namespaces if !@namespaces.nil? && @namespaces.size > 0
102
+ @default_param[:metas] ||= @metas if !@metas.nil? && @metas.size > 0
103
+ end
104
+
105
+ def restore_metas
106
+ @stylesheets = @default_param[:styleheets] || @stylesheets
107
+ @title = @default_param[:title] || @title
108
+ @lang = @default_param[:lang] || @lang
109
+ @paragraph_style = @default_param[:paragraph_style] || @paragraph_style
110
+ @namespaces = @default_param[:namespaces] || @namespaces
111
+ @metas = @default_param[:metas] || @metas
91
112
  end
92
113
 
93
114
  def <<(text)
@@ -100,6 +121,7 @@ module NoraMark
100
121
  def set_toc toc
101
122
  @pages.set_toc toc
102
123
  end
124
+
103
125
  def result
104
126
  if !@pages.last.frozen?
105
127
  end_html
@@ -28,6 +28,12 @@ module NoraMark
28
28
  }
29
29
  end
30
30
  def write(node)
31
+ if node.yaml.keys.map(&:to_sym).include? :stylesheets
32
+ @context.stylesheets = []
33
+ end
34
+ if node.yaml.keys.map(&:to_sym).include? :meta
35
+ @context.metas = []
36
+ end
31
37
  node.yaml.each {
32
38
  |k,v|
33
39
  writer = @writers[k.to_sym]
@@ -26,6 +26,7 @@ module NoraMark
26
26
  node_preprocessor: proc do |node|
27
27
  @context.end_html
28
28
  if node.first_child.class == Frontmatter
29
+ @context.save_metas
29
30
  frontmatter = node.first_child
30
31
  frontmatter_writer.write frontmatter
31
32
  frontmatter.remove
@@ -34,9 +34,9 @@ module NoraMark
34
34
  nora =
35
35
  NoraMark::Document.parse(
36
36
  File.open(t.source),
37
- :lang => @lang,
37
+ :lang => @lang.to_s,
38
38
  :sequence_format => "%0#{page_number_digits}d",
39
- :document_name=>t.name.sub(/_[0-9]{3}\.xhtml/, '')) do
39
+ :document_name=>t.name.sub(/_[0-9]{#{page_number_digits}}\.xhtml/, '')) do
40
40
  |doc|
41
41
  @preprocessors.each do
42
42
  |prepro|
@@ -1,3 +1,3 @@
1
1
  module NoraMark
2
- VERSION = "0.2beta14"
2
+ VERSION = "0.2beta15"
3
3
  end
@@ -481,6 +481,7 @@ describe NoraMark::Document do
481
481
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
482
482
  converted = noramark.html
483
483
  expect(converted.size).to eq 3
484
+
484
485
  body1 = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
485
486
  expect(body1.element_children[0].selector_and_children)
486
487
  .to eq(
@@ -500,7 +501,7 @@ describe NoraMark::Document do
500
501
  )
501
502
 
502
503
  head3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head')
503
- expect(head3.element_children[0].a).to eq ['title', 'page changed']
504
+ expect(head3.element_children[0].a).to eq ['title', 'the title']
504
505
  body3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:body')
505
506
  expect(body3.element_children[0].selector_and_children)
506
507
  .to eq(
@@ -923,6 +924,70 @@ EOF
923
924
  ['h1',"2nd page"])
924
925
  end
925
926
 
927
+ it 'specify stylesheet on each page' do
928
+ text = <<EOF
929
+ ---
930
+ title: the document title
931
+ stylesheets: default.css
932
+ ---
933
+ 1st page.
934
+ newpage:
935
+ ---
936
+ title: page 2
937
+ stylesheets: alternative.css
938
+ ---
939
+ 2nd page with alternative stylesheet.
940
+ newpage:
941
+ 3rd page with default css.
942
+ EOF
943
+ noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title', paragraph_style: :use_paragraph_group)
944
+ converted = noramark.html
945
+ # 1st page
946
+ head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
947
+ expect(head.element_children[0].a).to eq ['title', 'the document title']
948
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='default.css']", '']
949
+ # 2nd page
950
+ head = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
951
+ expect(head.element_children[0].a).to eq ['title', 'page 2']
952
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='alternative.css']", '']
953
+ # 3rd page
954
+ head = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head')
955
+ expect(head.element_children[0].a).to eq ['title', 'the title']
956
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='default.css']", '']
957
+ end
958
+
959
+ it 'specify stylesheet on each page, with default supplied' do
960
+ text = <<EOF
961
+ ---
962
+ title: document title 1st
963
+ ---
964
+ 1st page.
965
+ newpage:
966
+ ---
967
+ title: page 2
968
+ stylesheets: alternative.css
969
+ ---
970
+ 2nd page with alternative stylesheet.
971
+ newpage:
972
+ 3rd page with default css.
973
+ EOF
974
+ noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title', paragraph_style: :use_paragraph_group, stylesheets: ['default.css'])
975
+ converted = noramark.html
976
+ # 1st page
977
+ head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
978
+ expect(head.element_children[0].a).to eq ['title', 'document title 1st']
979
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='default.css']", '']
980
+ # 2nd page
981
+ head = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
982
+ expect(head.element_children[0].a).to eq ['title', 'page 2']
983
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='alternative.css']", '']
984
+ # 3rd page
985
+ head = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head')
986
+ expect(head.element_children[0].a).to eq ['title', 'the title']
987
+ expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='default.css']", '']
988
+ end
989
+
990
+
926
991
  it 'ignore comments' do
927
992
  text = "// この行はコメントです\nここから、パラグラフがはじまります。\n // これもコメント\n「二行目です。」\n三行目です。\n\n// これもコメント\n\n ここから、次のパラグラフです。\n// 最後のコメントです"
928
993
  noramark = NoraMark::Document.parse(text, lang: 'ja', title: 'the title')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nora_mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2beta14
4
+ version: 0.2beta15
5
5
  platform: ruby
6
6
  authors:
7
7
  - KOJIMA Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-23 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kpeg