• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-rdf / rdf-rdfa / 11317674118

13 Oct 2024 09:03PM UTC coverage: 90.142%. Remained the same
11317674118

push

github

gkellogg
Remove duplicate datatype in writer lang option

1079 of 1197 relevant lines covered (90.14%)

1322.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/rdf/rdfa/writer/haml_templates.rb
1
# Default HAML templates used for generating output from the writer
2
module RDF::RDFa
2✔
3
  class Writer
2✔
4
    # The default set of HAML templates used for RDFa code generation
5
   BASE_HAML = {
6
     identifier: "base",
2✔
7
      # Document
8
      # Locals: language, title, prefix, base, subjects
9
      # Yield: subjects.each
10
      doc: %q(
11
        !!! XML
12
        !!! 5
13
        %html{**{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}.compact}
14
          - if base || title
15
            %head
16
              - if base
17
                %base{**{href: base}.compact}
18
              - if title
19
                %title= title
20
          %body
21
            - subjects.map do |subject|
22
              != yield(subject)
23
      ),
24

25
      # Output for non-leaf resources
26
      # Note that @about may be omitted for Nodes that are not referenced
27
      #
28
      # If _rel_ and _resource_ are not nil, the tag will be written relative
29
      # to a previous subject. If _element_ is :li, the tag will be written
30
      # with <li> instead of <div>.
31
      #
32
      # Locals: subject, typeof, predicates, rel, element, inlist
33
      # Yield: predicates.each
34
      subject: %q(
35
        - if element == :li
36
          %li{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
37
            - if typeof
38
              %span.type!= typeof
39
            - predicates.each do |predicate|
40
              != yield(predicate)
41
        - else
42
          %div{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
43
            - if typeof
44
              %span.type!= typeof
45
            - predicates.each do |predicate|
46
              != yield(predicate)
47
      ),
48

49
      # Output for single-valued properties
50
      # Locals: predicate, object, inlist
51
      # Yields: object
52
      # If nil is returned, render as a leaf
53
      # Otherwise, render result
54
      property_value: %q(
55
        - if heading_predicates.include?(predicate) && object.literal?
56
          %h1{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
57
        - else
58
          %div.property
59
            %span.label
60
              = get_predicate_name(predicate)
61
            - if res = yield(object)
62
              != res
63
            - elsif get_curie(object) == 'rdf:nil'
64
              %span{rel: get_curie(predicate), inlist: ''}
65
            - elsif object.node?
66
              %span{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
67
            - elsif object.uri?
68
              %a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
69
            - elsif object.datatype == RDF.XMLLiteral
70
              %span{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}<!= get_value(object)
71
            - else
72
              %span{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
73
      ),
74

75
      # Output for multi-valued properties
76
      # Locals: predicate, :objects, :inlist
77
      # Yields: object for leaf resource rendering
78
      property_values:  %q(
79
        %div.property
80
          %span.label
81
            = get_predicate_name(predicate)
82
          %ul
83
            - objects.each do |object|
84
              - if res = yield(object)
85
                != res
86
              - elsif object.node?
87
                %li{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
88
              - elsif object.uri?
89
                %li
90
                  %a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
91
              - elsif object.datatype == RDF.XMLLiteral
92
                %li{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_curie(object.datatype), inlist: inlist}.compact}<!= get_value(object)
93
              - else
94
                %li{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
95
      ),
96
    }
97

98
    # An alternative, minimal HAML template for RDFa code generation.
99
    # This version does not perform recursive object generation and does not attempt
100
    # to create human readable output.
101
    MIN_HAML = {
102
      identifier: "min",
2✔
103
      # Document
104
      # Locals: language, title, prefix, base, subjects
105
      # Yield: subjects.each
106
      doc: %q(
107
        !!! XML
108
        !!! 5
109
        %html{**{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}.compact}
110
          - if base
111
            %head
112
              %base{*{href: base}.compact}
113
          %body
114
            - subjects.each do |subject|
115
              != yield(subject)
116
      ),
117

118
      # Output for non-leaf resources
119
      # Note that @about may be omitted for Nodes that are not referenced
120
      #
121
      # Locals: about, typeof, predicates, :inlist
122
      # Yield: predicates.each
123
      subject: %q(
124
        %div{**{rel: rel, resource: (about || resource), typeof: typeof}.compact}
125
          - predicates.each do |predicate|
126
            != yield(predicate)
127
      ),
128

129
      # Output for single-valued properties.
130
      # This version does not perform a recursive call, and renders all objects as leafs.
131
      # Locals: predicate, object, inlist
132
      # Yields: object
133
      # If nil is returned, render as a leaf
134
      # Otherwise, render result
135
      property_value: %q(
136
      - if res = yield(object)
137
        != res
138
      - elsif get_curie(object) == 'rdf:nil'
139
        %span{rel: get_curie(predicate), inlist: ''}
140
      - elsif object.node?
141
        %span{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
142
      - elsif object.uri?
143
        %a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
144
      - elsif object.datatype == RDF.XMLLiteral
145
        %span{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}<!= get_value(object)
146
      - else
147
        %span{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
148
      )
149
    }
150

151
    DISTILLER_HAML = {
152
      identifier: "distiller",
2✔
153
      # Document
154
      # Locals: language, title, prefix, base, subjects
155
      # Yield: subjects.each
156
      doc: %q(
157
        !!! XML
158
        !!! 5
159
        %html{**{xmlns: "http://www.w3.org/1999/xhtml", lang: lang, prefix: prefix}.compact}
160
          - if base || title
161
            %head
162
              - if base
163
                %base{href: base}
164
              - if title
165
                %title= title
166
              %link{rel: "stylesheet", href: "http://rdf.greggkellogg.net/css/distiller.css", type: "text/css"}
167
              %script{src: "https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js", type: "text/javascript"}
168
              %script{src: "http://rdf.greggkellogg.net/js/distiller.js", type: "text/javascript"}
169
          %body
170
            - if base
171
              %p= "RDFa serialization URI base: &lt;#{base}&gt;"
172
            - subjects.each do |subject|
173
              != yield(subject)
174
            %footer
175
              %p= "Written by <a href='https://rubygems.org/gems/rdf-rdfa'>RDF::RDFa</a> version #{RDF::RDFa::VERSION}"
176
      ),
177

178
      # Output for non-leaf resources
179
      # Note that @about may be omitted for Nodes that are not referenced
180
      #
181
      # If _rel_ and _resource_ are not nil, the tag will be written relative
182
      # to a previous subject. If _element_ is :li, the tag will be written
183
      # with <li> instead of <div>.
184
      #
185
      # Note that @rel and @resource can be used together, or @about and @typeof, but
186
      # not both.
187
      #
188
      # Locals: subject, typeof, predicates, rel, element, inlist
189
      # Yield: predicates.each
190
      subject: %q(
191
        - if element == :li
192
          %li{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
193
            - if typeof
194
              %span.type!= typeof
195
            %table.properties
196
              - predicates.each do |predicate|
197
                != yield(predicate)
198
        - elsif rel
199
          %td{**{rel: rel, resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
200
            - if typeof
201
              %span.type!= typeof
202
            %table.properties
203
              - predicates.each do |predicate|
204
                != yield(predicate)
205
        - else
206
          %div{**{resource: (about || resource), typeof: typeof, inlist: inlist}.compact}
207
            - if typeof
208
              %span.type!= typeof
209
            %table.properties
210
              - predicates.each do |predicate|
211
                != yield(predicate)
212
      ),
213

214
      # Output for single-valued properties
215
      # Locals: predicate, object, inlist
216
      # Yields: object
217
      # If nil is returned, render as a leaf
218
      # Otherwise, render result
219
      property_value: %q(
220
        - if heading_predicates.include?(predicate) && object.literal?
221
          %h1{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
222
        - else
223
          %tr.property
224
            %td.label
225
              = get_predicate_name(predicate)
226
            - if res = yield(object)
227
              != res
228
            - elsif get_curie(object) == 'rdf:nil'
229
              %td{rel: get_curie(predicate), inlist: ''}= "Empty"
230
            - elsif object.node?
231
              %td{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
232
            - elsif object.uri?
233
              %td
234
                %a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
235
            - elsif object.datatype == RDF.XMLLiteral
236
              %td{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}<!= get_value(object)
237
            - else
238
              %td{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
239
      ),
240

241
      # Output for multi-valued properties
242
      # Locals: predicate, objects, inliste
243
      # Yields: object for leaf resource rendering
244
      property_values:  %q(
245
        %tr.property
246
          %td.label
247
            = get_predicate_name(predicate)
248
          %td
249
            %ul
250
              - objects.each do |object|
251
                - if res = yield(object)
252
                  != res
253
                - elsif object.node?
254
                  %li{**{property: get_curie(predicate), resource: get_curie(object), inlist: inlist}.compact}= get_curie(object)
255
                - elsif object.uri?
256
                  %li
257
                    %a{**{property: get_curie(predicate), href: object.to_s, inlist: inlist}.compact}= object.to_s
258
                - elsif object.datatype == RDF.XMLLiteral
259
                  %li{**{property: get_curie(predicate), lang: get_lang(object), datatype: get_curie(object.datatype), inlist: inlist}.compact}<!= get_value(object)
260
                - else
261
                  %li{**{property: get_curie(predicate), content: get_content(object), lang: get_lang(object), datatype: get_dt_curie(object), inlist: inlist}.compact}= escape_entities(get_value(object))
262
      ),
263
    }
264
    HAML_TEMPLATES = {base: BASE_HAML, min: MIN_HAML, distiller: DISTILLER_HAML}
2✔
265
    DEFAULT_HAML = BASE_HAML
2✔
266
  end
267
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc