hierogloss 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0ddc0d217ce2338569073c4d5da2259a595b62b
4
- data.tar.gz: a7f2c0564b348abcc6c864796ad69873896079a4
3
+ metadata.gz: 2217a6d05d499f86580c6cab5f2125b6d2a2be61
4
+ data.tar.gz: 1271a83c6216b0e156e4d0db70d7cff4161b5501
5
5
  SHA512:
6
- metadata.gz: 740be2d088f038a3a2d5ab40fc898799890ccba066047d293124532a62043372c6eebe28f75f9f23c7ab3d238b498a1c40e3e018ba9cbe27ad3e82a734ef77af
7
- data.tar.gz: 0faa6a5486c3b58c9ac54e6c65028534ffe42a9472dbd782452887d525c439dbda57f009bf450d33e445798209d79c689bcd712712fe714062490522983b324c
6
+ metadata.gz: 00e1516a717baec63b0b0b7f41916cd3082d3300db386123bdc79e622813fb316050de6cd43b642e356a6bd3f90b405fbfc17f7ac182d8b2c37235124d20c1ba
7
+ data.tar.gz: ba57a23e71dc632fe92fc63960270cda4d1dc555107a30c6e381e17ed2b38d5de40825fab1e3463b1df72c618c87bc5afc381f97f956c2f3601ce61d052fe8a3
data/README.md CHANGED
@@ -12,7 +12,7 @@ write:
12
12
  This example is based on one in Allen's excellent [Middle Egyptian: An
13
13
  Introduction to the Language and Culture of Hieroglyphs][allen].
14
14
 
15
- H: z:A1*Z1 | 𓊃:𓏏*𓁐 | 𓂋:𓏤-𓊪:𓅱
15
+ H: z:A1*Z1 | 𓊃:𓏏*𓁐 | 𓂋:𓏤-𓊪𓅱
16
16
  L: s | s.t | r-pw
17
17
  G: man | woman | whichever
18
18
  T: either [a] man or [a] woman
@@ -27,8 +27,9 @@ be presented in an appropriate font with Unicode characters.
27
27
 
28
28
  You can render this as HTML by running:
29
29
 
30
- hierogloss example.md > example.html
30
+ hierogloss -i example.md > example.html
31
31
 
32
+ The `-i` flag causes `hierogloss` to render the hieroglyphs as images.
32
33
  This will give you the following:
33
34
 
34
35
  > ![](examples/disjunction.png)
data/bin/hierogloss CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'optparse'
4
4
  require 'hierogloss'
5
5
 
6
- options = { format: 'html' }
6
+ options = { format: 'html', images: false }
7
7
 
8
8
  OptionParser.new do |opts|
9
9
  opts.banner = "Usage: hierogloss [options] files..."
@@ -13,9 +13,15 @@ OptionParser.new do |opts|
13
13
  " (defaults to html)") do |format|
14
14
  options[:format] = format
15
15
  end
16
+
17
+ opts.on("-i", "--[no-]images",
18
+ "Use inline images to render hieroglyphs",
19
+ " (defaults to off)") do |images|
20
+ options[:images] = images
21
+ end
16
22
  end.parse!
17
23
 
18
- args = { input: 'hierogloss' }
24
+ args = { input: 'hierogloss', use_images_for_signs: options[:images] }
19
25
  if options[:format] == 'html'
20
26
  args[:template] =
21
27
  File.join(File.dirname(__FILE__), '..', 'data', 'hierogloss.html.erb')
@@ -3,7 +3,7 @@
3
3
  This example is based on one in Allen's excellent [Middle Egyptian: An
4
4
  Introduction to the Language and Culture of Hieroglyphs][allen].
5
5
 
6
- H: z:A1*Z1 | 𓊃:𓏏*𓁐 | 𓂋:𓏤-𓊪:𓅱
6
+ H: z:A1*Z1 | 𓊃:𓏏*𓁐 | 𓂋:𓏤-𓊪𓅱
7
7
  L: s | s.t | r-pw
8
8
  G: man | woman | whichever
9
9
  T: either [a] man or [a] woman
Binary file
@@ -27,12 +27,12 @@ module Hierogloss
27
27
  nil
28
28
  end
29
29
 
30
- def to_kramdown
30
+ def to_kramdown(options)
31
31
  attrs = attributes
32
32
  tr = Kramdown::Element.new(:tr, nil, attrs)
33
33
  cells.each do |c|
34
34
  td = Kramdown::Element.new(:td)
35
- children = cell_to_kramdown(c)
35
+ children = cell_to_kramdown(c, options)
36
36
  if children.kind_of?(Array)
37
37
  td.children.concat(children)
38
38
  else
@@ -43,7 +43,7 @@ module Hierogloss
43
43
  tr
44
44
  end
45
45
 
46
- def cell_to_kramdown(cell)
46
+ def cell_to_kramdown(cell, options)
47
47
  Kramdown::Element.new(:text, cell)
48
48
  end
49
49
 
@@ -71,13 +71,17 @@ module Hierogloss
71
71
  @cells ||= raw_cells.map {|c| Hierogloss::MdC.parse(c) }
72
72
  end
73
73
 
74
- def cell_to_kramdown(cell)
75
- cell.to_linear_hieroglyphs.chars.map do |c|
76
- gardiner = Dictionary.sign_to_gardiner(c)
77
- unless gardiner.nil? || UNLINKED[c]
78
- search_link("Signe:#{gardiner}", c)
79
- else
80
- Kramdown::Element.new(:text, c)
74
+ def cell_to_kramdown(cell, options)
75
+ if options[:use_images_for_signs]
76
+ Kramdown::Element.new(:img, nil, 'src' => cell.to_mdc_image_url)
77
+ else
78
+ cell.to_linear_hieroglyphs.chars.map do |c|
79
+ gardiner = Dictionary.sign_to_gardiner(c)
80
+ unless gardiner.nil? || UNLINKED[c]
81
+ search_link("Signe:#{gardiner}", c)
82
+ else
83
+ Kramdown::Element.new(:text, c)
84
+ end
81
85
  end
82
86
  end
83
87
  end
@@ -107,7 +111,7 @@ module Hierogloss
107
111
  'hgls-l'
108
112
  end
109
113
 
110
- def cell_to_kramdown(cell)
114
+ def cell_to_kramdown(cell, options)
111
115
  fancy = self.class.fancy(cell)
112
116
  search_link(Dictionary.headword(cell), fancy)
113
117
  end
@@ -129,7 +133,7 @@ module Hierogloss
129
133
  'hgls-t'
130
134
  end
131
135
 
132
- def to_kramdown
136
+ def to_kramdown(options)
133
137
  em = Kramdown::Element.new(:em, nil)
134
138
  em.children << Kramdown::Element.new(:text, text)
135
139
  em
@@ -155,7 +159,7 @@ module Hierogloss
155
159
  end
156
160
  end
157
161
 
158
- def to_kramdown
162
+ def to_kramdown(options={})
159
163
  result = []
160
164
  # Neither Kramdown nor BBCode support rowspans, so we'll just cheat
161
165
  # for now.
@@ -164,7 +168,7 @@ module Hierogloss
164
168
  rows.each do |r|
165
169
  class_attr = "hgls-gloss #{r.class_attr}"
166
170
  p = Kramdown::Element.new(:p, nil, 'class' => class_attr)
167
- p.children << r.to_kramdown
171
+ p.children << r.to_kramdown(options)
168
172
  result << p
169
173
  end
170
174
  else
@@ -172,7 +176,7 @@ module Hierogloss
172
176
  alignment: [])
173
177
  tbody = Kramdown::Element.new(:tbody)
174
178
  table.children << tbody
175
- rows.each {|r| tbody.children << r.to_kramdown }
179
+ rows.each {|r| tbody.children << r.to_kramdown(options) }
176
180
  result << table
177
181
  end
178
182
  end
@@ -4,6 +4,16 @@ module Hierogloss
4
4
  #:nodoc: Our parser for the Manuel de Codage format.
5
5
  module MdC
6
6
  class Block
7
+ protected
8
+
9
+ # This whole precedence business may need more test cases further work.
10
+ def maybe_parens(current, context, str)
11
+ if current < context
12
+ "(#{str})"
13
+ else
14
+ str
15
+ end
16
+ end
7
17
  end
8
18
 
9
19
  class Sign < Block
@@ -33,6 +43,27 @@ module Hierogloss
33
43
  end
34
44
  end
35
45
 
46
+ class Composed < Block
47
+ attr_reader :base, :composed
48
+
49
+ def initialize(base, composed)
50
+ @base = base
51
+ @composed = composed
52
+ end
53
+
54
+ def to_debug
55
+ [:composed, base.to_debug, composed.to_debug]
56
+ end
57
+
58
+ def to_linear_hieroglyphs
59
+ [base.to_linear_hieroglyphs, composed.to_linear_hieroglyphs]
60
+ end
61
+
62
+ def to_mdc(precedence)
63
+ maybe_parens(3, precedence, "#{base.to_mdc(3)}&#{composed.to_mdc(3)}")
64
+ end
65
+ end
66
+
36
67
  class Group < Block
37
68
  attr_reader :blocks
38
69
 
@@ -47,17 +78,6 @@ module Hierogloss
47
78
  def to_linear_hieroglyphs
48
79
  blocks.map {|b| b.to_linear_hieroglyphs }
49
80
  end
50
-
51
- protected
52
-
53
- # This whole precedence business may need more test cases further work.
54
- def maybe_parens(current, context, str)
55
- if current < context
56
- "(#{str})"
57
- else
58
- str
59
- end
60
- end
61
81
  end
62
82
 
63
83
  class Sequence < Group
@@ -85,6 +105,11 @@ module Hierogloss
85
105
  def to_mdc
86
106
  blocks.map {|b| b.to_mdc(0) }.join("-")
87
107
  end
108
+
109
+ def to_mdc_image_url
110
+ esc = URI.escape(to_mdc, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
111
+ "http://i.hierogloss.net/mdc/#{esc}.png"
112
+ end
88
113
  end
89
114
 
90
115
  class Parser < Parslet::Parser
@@ -97,12 +122,15 @@ module Hierogloss
97
122
  rule(:unicode_sign) { match('[\u{13000}-\u{1342F}]') }
98
123
  rule(:sign) { (alpha_sign | unicode_sign).as(:sign) >> space? }
99
124
 
125
+ # Signs with special composition behavior, as per JSesh.
126
+ rule(:composed) { sign.as(:base) >> str('&') >> atomic.as(:composed) }
127
+
100
128
  # Parenthesized blocks.
101
129
  rule(:parens) { str('(') >> space? >> sequence >> str(')') >> space? }
102
130
 
103
131
  # "Terminal" chunks in our expression grammar, which will match
104
132
  # an actual, concrete symbol in the first position.
105
- rule(:atomic) { sign | parens }
133
+ rule(:atomic) { composed | sign | parens }
106
134
 
107
135
  # A list of items with separators between them.
108
136
  def separated(item, separator)
@@ -132,6 +160,9 @@ module Hierogloss
132
160
 
133
161
  rule(head: subtree(:head), rest: sequence(:rest)) { [head].concat(rest) }
134
162
  rule(sign: simple(:sign)) { Sign.new(sign.to_s) }
163
+ rule(base: simple(:base), composed: simple(:composed)) do
164
+ Composed.new(base, composed)
165
+ end
135
166
  rule(stack: subtree(:list)) {|d| lists_as(Stack, d[:list]) }
136
167
  rule(juxtaposed: subtree(:list)) {|d| lists_as(Sequence, d[:list]) }
137
168
  end
@@ -1,3 +1,3 @@
1
1
  module Hierogloss
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -27,7 +27,8 @@ module Kramdown
27
27
  def parse_gloss
28
28
  start_line_number = @src.current_line_number
29
29
  data = @src.scan(self.class::GLOSS_MATCH)
30
- @tree.children.concat(::Hierogloss::Gloss.new(data).to_kramdown)
30
+ elems = ::Hierogloss::Gloss.new(data).to_kramdown(@options)
31
+ @tree.children.concat(elems)
31
32
  true
32
33
  end
33
34
 
data/test/test_gloss.rb CHANGED
@@ -42,4 +42,8 @@ EOD
42
42
  assert(kramdown.length > 0)
43
43
  kramdown.each {|k| assert_instance_of(Kramdown::Element, k) }
44
44
  end
45
+
46
+ def test_should_be_convertible_to_kramdown_with_images
47
+ kramdown = @gloss.to_kramdown(use_images_for_signs: true)
48
+ end
45
49
  end
data/test/test_mdc.rb CHANGED
@@ -29,6 +29,10 @@ class TestCodage < MiniTest::Test
29
29
  assert_parse([[:stack, "𓇾", ["𓏤", "𓈇"]]], "𓇾:𓏤*𓈇")
30
30
  end
31
31
 
32
+ def test_should_parse_composed_signs
33
+ assert_parse([[:composed, "𓅱", "𓏏"]], "𓅱&𓏏")
34
+ end
35
+
32
36
  def test_should_honor_parens
33
37
  assert_parse([[:stack, ["p", [:stack, "t", "Z4"]], "pt"]], "p*(t:Z4):pt")
34
38
  end
@@ -40,6 +44,7 @@ class TestCodage < MiniTest::Test
40
44
  def test_should_convert_mdc_to_linear_hieroglyphs
41
45
  assert_linear_hieroglyphs("𓆓𓂧𓈖", "𓆓:𓂧𓈖")
42
46
  assert_linear_hieroglyphs("𓊪𓏏𓏭𓇯", "p*(t:Z4):pt")
47
+ assert_linear_hieroglyphs("𓅱𓏏", "𓅱&𓏏")
43
48
  end
44
49
 
45
50
  def assert_mdc(expected, input)
@@ -49,7 +54,17 @@ class TestCodage < MiniTest::Test
49
54
  def test_should_convert_mdc_to_mdc_string
50
55
  assert_mdc("D:d-n", "𓆓:𓂧𓈖")
51
56
  assert_mdc("p*(t:Z4):pt", "p*(t:Z4):pt")
57
+ assert_mdc("w&t", "𓅱&𓏏")
52
58
  # Compound signs are always placed in parens.
53
59
  assert_mdc("(N33*N33:N33*N33)", "𓃌")
54
60
  end
61
+
62
+ def assert_mdc_image_url(expected, input)
63
+ assert_equal(expected, Hierogloss::MdC.parse(input).to_mdc_image_url)
64
+ end
65
+
66
+ def test_should_convert_to_mdc_image_url
67
+ assert_mdc_image_url("http://i.hierogloss.net/mdc/p*(t%3AZ4)%3Apt.png",
68
+ "p*(t:Z4):pt")
69
+ end
55
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hierogloss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kidd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown