correspondence-markup 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ grammar CorrespondenceMarkupLanguage
|
|
5
5
|
include CorrespondenceMarkup
|
6
6
|
|
7
7
|
rule structure_groups
|
8
|
-
s groups:("
|
8
|
+
s groups:("(" structure_group ")" s)*
|
9
9
|
{
|
10
10
|
def value
|
11
11
|
groups.elements.map {|e| e.structure_group.value}
|
@@ -14,7 +14,7 @@ grammar CorrespondenceMarkupLanguage
|
|
14
14
|
end
|
15
15
|
|
16
16
|
rule structure_group
|
17
|
-
s structures:("
|
17
|
+
s description:structure_group_description? s structures:("{" structure "}" s)*
|
18
18
|
{
|
19
19
|
def value
|
20
20
|
structureObjects = structures.elements.map {|e| e.structure.value}
|
@@ -22,12 +22,32 @@ grammar CorrespondenceMarkupLanguage
|
|
22
22
|
end
|
23
23
|
}
|
24
24
|
end
|
25
|
+
|
26
|
+
rule structure_group_description
|
27
|
+
"#" s [^{\n]* "\n"
|
28
|
+
end
|
25
29
|
|
26
30
|
rule structure
|
27
|
-
|
31
|
+
class:structure_class s itemGroups:("[" item_group "]" s)*
|
32
|
+
{
|
33
|
+
def value
|
34
|
+
itemGroupObjects = itemGroups.elements.map {|e| e.item_group.value}
|
35
|
+
CorrespondenceMarkup::Structure.new(itemGroupObjects)
|
36
|
+
end
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
rule structure_class
|
41
|
+
([a-zA-Z] [a-zA-Z0-9_-]*)?
|
42
|
+
end
|
43
|
+
|
44
|
+
rule item_group
|
45
|
+
optional_id:(id:[A-Z]* ":")? components:(item / non_item)*
|
28
46
|
{
|
29
47
|
def value
|
30
|
-
|
48
|
+
group_id = optional_id.elements ? optional_id.elements[0].text_value : ""
|
49
|
+
componentObjects = components.elements.map {|e| e.value(group_id)}
|
50
|
+
CorrespondenceMarkup::ItemGroup.new(group_id, componentObjects)
|
31
51
|
end
|
32
52
|
}
|
33
53
|
end
|
@@ -35,17 +55,21 @@ grammar CorrespondenceMarkupLanguage
|
|
35
55
|
rule non_item
|
36
56
|
text:text
|
37
57
|
{
|
38
|
-
def value
|
58
|
+
def value(group_id = "")
|
39
59
|
CorrespondenceMarkup::NonItem.new(text.value)
|
40
60
|
end
|
41
61
|
}
|
42
62
|
end
|
43
63
|
|
44
64
|
rule item
|
45
|
-
"[" id:
|
65
|
+
"[" id:item_id S text:text "]"
|
46
66
|
{
|
47
|
-
def value
|
48
|
-
|
67
|
+
def value(group_id = "")
|
68
|
+
item_id = id.text_value
|
69
|
+
if !item_id.match(/[A-Z]/)
|
70
|
+
item_id = group_id + item_id
|
71
|
+
end
|
72
|
+
CorrespondenceMarkup::Item.new(item_id, text.value)
|
49
73
|
end
|
50
74
|
}
|
51
75
|
end
|
@@ -59,15 +83,10 @@ grammar CorrespondenceMarkupLanguage
|
|
59
83
|
}
|
60
84
|
end
|
61
85
|
|
62
|
-
rule
|
63
|
-
[0-9]+
|
64
|
-
{
|
65
|
-
def value
|
66
|
-
text_value.to_i
|
67
|
-
end
|
68
|
-
}
|
86
|
+
rule item_id
|
87
|
+
[A-Z]* [0-9]+
|
69
88
|
end
|
70
|
-
|
89
|
+
|
71
90
|
rule s
|
72
91
|
[\s\n\r\t]*
|
73
92
|
end
|
@@ -78,20 +78,42 @@ module CorrespondenceMarkup
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
# A group of items & non-items that will form part of a structure
|
82
|
+
class ItemGroup
|
83
|
+
attr_reader :id, :content
|
84
|
+
|
85
|
+
def initialize(id, content)
|
86
|
+
@id = id
|
87
|
+
@content = content
|
88
|
+
end
|
89
|
+
|
90
|
+
def ==(otherItemGroup)
|
91
|
+
otherItemGroup.class == ItemGroup && otherItemGroup.id == @id && otherItemGroup.content == @content
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_html(options={})
|
95
|
+
"<div class=\"item-group\" data-group-id=\"#{@id}\">\n " +
|
96
|
+
@content.map{|x| x.to_html(options)}.join("") + "\n</div>\n"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
81
100
|
# A structure, containing a sequence of items and non-items
|
82
101
|
class Structure
|
83
|
-
attr_reader :
|
102
|
+
attr_reader :item_groups
|
84
103
|
|
85
|
-
def initialize(
|
86
|
-
@
|
104
|
+
def initialize(item_groups)
|
105
|
+
@item_groups = item_groups
|
87
106
|
end
|
88
107
|
|
89
108
|
def ==(otherStructure)
|
90
|
-
otherStructure.class == Structure && otherStructure.
|
109
|
+
otherStructure.class == Structure && otherStructure.item_groups == @item_groups
|
91
110
|
end
|
92
111
|
|
93
112
|
def to_html(options={})
|
94
|
-
|
113
|
+
itemGroupHtmls = @item_groups.map{|x| x.to_html(options)}
|
114
|
+
"<div class=\"structure\">\n " +
|
115
|
+
itemGroupHtmls.join("").chomp("\n").gsub("\n", "\n ") +
|
116
|
+
"\n</div>\n"
|
95
117
|
end
|
96
118
|
|
97
119
|
end
|
@@ -11,7 +11,11 @@ module CorrespondenceMarkup
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def compile_structure_groups(markup)
|
14
|
-
@parser.parse(markup, root: :structure_groups)
|
14
|
+
syntax_tree = @parser.parse(markup, root: :structure_groups)
|
15
|
+
if(syntax_tree.nil?)
|
16
|
+
raise Exception, "Parse error: #{@parser.failure_reason}"
|
17
|
+
end
|
18
|
+
syntax_tree.value
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correspondence-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Use to generate HTML pages containing structure groups, structures and
|
15
15
|
items as used by correspondence.js.
|
@@ -38,7 +38,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
38
|
version: '0'
|
39
39
|
segments:
|
40
40
|
- 0
|
41
|
-
hash:
|
41
|
+
hash: -240696941
|
42
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|