Skip to content
Draft
38 changes: 27 additions & 11 deletions source/_plugins/include_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ def render(context)
end
indent = integer_option(options, 'indent')

unless from && to
raise ArgumentError, "include_lines: must specify from/to (1-indexed), e.g. {% include_lines path from:11 to:35 %}"
end

if from < 1 || to < 1
raise ArgumentError, "include_lines: from/to must be >= 1 (got from:#{from} to:#{to})"
end
no_range_given = from.nil? && to.nil?

if to < from
raise ArgumentError, "include_lines: to must be >= from (got from:#{from} to:#{to})"
# If no from/to (or start/end aliases) are given, include the whole file.
# If only one of from/to is given, keep raising (ambiguous).
if !no_range_given && !(from && to)
raise ArgumentError, "include_lines: must specify from/to (1-indexed), e.g. {% include_lines path from:11 to:35 %}"
end

absolute_path = File.expand_path(path, source)
Expand All @@ -53,6 +49,19 @@ def render(context)
lines = File.read(absolute_path, encoding: 'UTF-8').split("\n", -1)
max_line = lines.length

if no_range_given
from = 1
to = max_line
end

if from < 1 || to < 1
raise ArgumentError, "include_lines: from/to must be >= 1 (got from:#{from} to:#{to})"
end

if to < from
raise ArgumentError, "include_lines: to must be >= from (got from:#{from} to:#{to})"
end

if from > max_line
raise ArgumentError, "include_lines: from (#{from}) is beyond end of file (#{max_line} lines): #{path}"
end
Expand Down Expand Up @@ -108,9 +117,16 @@ def unquote(value)

def integer_option(options, key)
return nil unless options.key?(key)
Integer(options[key])

raw = options[key]
return nil if raw.nil?

s = raw.to_s.strip
return nil if s.empty?

Integer(s, 10)
rescue ArgumentError
raise ArgumentError, "include_lines: #{key} must be an integer (got #{options[key].inspect})"
raise ArgumentError, "include_lines: #{key} must be an integer (got #{raw.inspect})"
end

def boolean_option(options, key)
Expand Down
9 changes: 6 additions & 3 deletions source/presentation/4.0/example/02_timeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
{
"id": "https://iiif.io/api/presentation/4.0/example/02/page/anno",
"type": "Annotation",
"motivation": "painting",
"motivation": ["painting"],
"body": {
"id": "https://fixtures.iiif.io/audio/indiana/mahler-symphony-3/CD1/medium/128Kbps.mp4",
"type": "Sound",
"type": "Audio",
"format": "audio/mp4",
"duration": 1985.024
},
"target": "https://iiif.io/api/presentation/4.0/example/02"
"target": {
"id": "https://iiif.io/api/presentation/4.0/example/02",
"type": "Timeline"
}
}
]
}
Expand Down
42 changes: 42 additions & 0 deletions source/presentation/4.0/example/03_canvas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"@context": "http://iiif.io/api/presentation/4/context.json",
"id": "https://iiif.io/api/presentation/4.0/example/03_canvas.json",
"type": "Manifest",
"label": {
"en": [
"Simplest Image Example (IIIF Presentation v4)"
]
},
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/03_canvas/canvas/p1",
"type": "Canvas",
"height": 1800,
"width": 1200,
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/03_canvas/page/p1/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/03_canvas/annotation/p0001-image",
"type": "Annotation",
"motivation": [ "painting" ],
"body": {
"id": "http://iiif.io/api/presentation/2.1/example/fixtures/resources/page1-full.png",
"type": "Image",
"format": "image/png",
"height": 1800,
"width": 1200
},
"target": {
"id": "https://iiif.io/api/presentation/4.0/example/03_canvas/canvas/p1",
"type": "Canvas"
}
}
]
}
]
}
]
}
50 changes: 50 additions & 0 deletions source/presentation/4.0/example/04_scene.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"@context": "http://iiif.io/api/presentation/4/context.json",
"id": "https://iiif.io/api/presentation/4.0/example/04_scene.json",
"type": "Manifest",
"label": {
"en": [
"Simplest Model Example (IIIF Presentation v4)"
]
},
"summary": {
"en": [
"Viewer should render the model at the scene origin and then add default lighting and camera"
]
},
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/scene/1",
"type": "Scene",
"label": {
"en": [
"A Scene"
]
},
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/scene/1/annotationPage/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/scene/1/annotationPage/1/anno/1",
"type": "Annotation",
"motivation": [
"painting"
],
"body": {
"id": "https://raw.githubusercontent.com/IIIF/3d/main/assets/astronaut/astronaut.glb",
"type": "Model",
"format": "model/gltf-binary"
},
"target": {
"id": "https://iiif.io/api/presentation/4.0/example/scene/1",
"type": "Scene"
}
}
]
}
]
}
]
}
78 changes: 78 additions & 0 deletions source/presentation/4.0/example/05_fragment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"@context": "http://iiif.io/api/presentation/4/context.json",
"id": "https://iiif.io/api/presentation/4.0/example/05_fragment.json",
"type": "Manifest",
"label": {
"en": [
"Koto, chess, calligraphy, and painting"
],
"ja": [
"琴棋書画図屏風"
]
},
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/05/canvas/p1",
"type": "Canvas",
"height": 3966,
"width": 8800,
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/05/page/p1/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/05/annotation/p0001-image",
"type": "Annotation",
"motivation": [
"painting"
],
"body": {
"id": "https://iiif.io/api/image/3.0/example/reference/36ca0a3370db128ec984b33d71a1543d-100320001004/full/max/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"height": 3966,
"width": 8800,
"service": [
{
"id": "https://iiif.io/api/image/3.0/example/reference/36ca0a3370db128ec984b33d71a1543d-100320001004",
"profile": "level1",
"type": "ImageService3"
}
]
},
"target": {
"id": "https://iiif.io/api/presentation/4.0/example/05/canvas/p1",
"type":"Canvas"
}
}
]
}
],
"annotations": [
{
"id": "https://iiif.io/api/presentation/4.0/example/05/page/p2/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/05/annotation/p0001-comment",
"type": "Annotation",
"motivation": [ "commenting" ],
"body": {
"id": "https://iiif.io/api/presentation/4.0/example/05/annotation/bodies/koto-body",
"type": "TextualBody",
"value": "Koto with a cover being carried",
"language": "en",
"format": "text/plain"
},
"target": {
"id": "https://iiif.io/api/presentation/4.0/example/05/canvas/p1#xywh=1650,1200,925,1250",
"type": "Canvas"
}
}
]
}
]
}
]
}
87 changes: 87 additions & 0 deletions source/presentation/4.0/example/06_specific_resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"@context": "http://iiif.io/api/presentation/4/context.json",
"id": "https://iiif.io/api/presentation/4.0/example/06_specific_resource.json",
"type": "Manifest",
"label": {
"en": [
"Koto, chess, calligraphy, and painting"
],
"ja": [
"琴棋書画図屏風"
]
},
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/06/canvas/p1",
"type": "Canvas",
"height": 3966,
"width": 8800,
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/06/page/p1/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/06/annotation/p0001-image",
"type": "Annotation",
"motivation": [
"painting"
],
"body": {
"id": "https://iiif.io/api/image/3.0/example/reference/36ca0a3370db128ec984b33d71a1543d-100320001004/full/max/0/default.jpg",
"type": "Image",
"format": "image/jpeg",
"height": 3966,
"width": 8800,
"service": [
{
"id": "https://iiif.io/api/image/3.0/example/reference/36ca0a3370db128ec984b33d71a1543d-100320001004",
"profile": "level1",
"type": "ImageService3"
}
]
},
"target": {
"id":"https://iiif.io/api/presentation/4.0/example/06/canvas/p1",
"type":"Canvas"
}
}
]
}
],
"annotations": [
{
"id": "https://iiif.io/api/presentation/4.0/example/06/page/p2/1",
"type": "AnnotationPage",
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/06/annotation/p0001-comment",
"type": "Annotation",
"motivation": [ "commenting" ],
"body": {
"id": "https://iiif.io/api/presentation/4.0/example/06/annotation/bodies/koto-body",
"type": "TextualBody",
"value": "Koto with a cover being carried",
"language": "en",
"format": "text/plain"
},
"target": {
"id": "https://iiif.io/api/presentation/4.0/example/06/resources/koto-sr",
"type": "SpecificResource",
"source": {
"id": "https://iiif.io/api/presentation/4.0/example/06/page/p1/1",
"type": "Canvas"
},
"selector": {
"id": "https://iiif.io/api/presentation/4.0/example/06/selectors/koto-selector",
"type": "FragmentSelector",
"value": "xywh=1650,1200,925,1250"
}
}
}
]
}
]
}
]
}
22 changes: 22 additions & 0 deletions source/presentation/4.0/example/07_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "https://iiif.io/api/presentation/4.0/example/07_collection.json",
"type": "Collection",
"label": { "en": [ "Top-level Collection" ] },
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/07_sub_collection.json",
"type": "Collection",
"label": { "en": [ "Sub-Collection 1" ] }
},
{
"id": "https://iiif.io/api/presentation/4.0/example/02_canvas.json",
"type": "Manifest",
"label": { "en": [ "Manifest 1" ] }
},
{
"id": "https://iiif.io/api/presentation/4.0/example/05_fragment.json",
"type": "Manifest",
"label": { "en": [ "Manifest 2" ] }
}
]
}
20 changes: 20 additions & 0 deletions source/presentation/4.0/example/07_sub_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id": "https://iiif.io/api/presentation/4.0/example/07_sub_collection.json",
"type": "Collection",
"label": {
"en": [
"Sub-Collection"
]
},
"items": [
{
"id": "https://iiif.io/api/presentation/4.0/example/06_specific_resource.json",
"type": "Manifest",
"label": {
"en": [
"Sub collection - Manifest 1"
]
}
}
]
}
Loading
Loading