Browse code

Add imgcap plugin

Cinan Rakosnik authored on 10/11/2013 at 16:11:21
Showing 3 changed files
... ...
@@ -12,6 +12,10 @@
12 12
   border: $border;
13 13
 }
14 14
 
15
+@mixin reset-shadow-box() {
16
+  @include shadow-box(0px, 0px, 0px);
17
+}
18
+
15 19
 @mixin selection($bg, $color: inherit, $text-shadow: none){
16 20
   * {
17 21
     &::-moz-selection { background: $bg; color: $color; text-shadow: $text-shadow; }
... ...
@@ -42,11 +42,28 @@ article {
42 42
     font-size: 2.0em; font-style: italic;
43 43
     line-height: 1.3em;
44 44
   }
45
-  img, video, .flash-video {
45
+  img, video, .flash-video, .caption-wrapper {
46 46
     @extend .flex-content;
47 47
     @extend .basic-alignment;
48 48
     @include shadow-box;
49
+
50
+    &.caption {
51
+ 	 @include reset-shadow-box;
52
+    }
49 53
   }
54
+
55
+  .caption-wrapper {
56
+	display: inline-block;
57
+	margin-bottom: 10px;
58
+	.caption-text {
59
+	  background: #fff;
60
+	  text-align: center;
61
+	  font-size: .8em;
62
+	  color: #666;
63
+	  display: block;
64
+	}
65
+  }
66
+
50 67
   video, .flash-video { margin: 0 auto 1.5em; }
51 68
   video { display: block; width: 100%; }
52 69
   .flash-video {
53 70
new file mode 100644
... ...
@@ -0,0 +1,42 @@
0
+# Title: Image tag with caption for Jekyll
1
+# Description: Easily output images with captions
2
+
3
+module Jekyll
4
+
5
+  class CaptionImageTag < Liquid::Tag
6
+    @img = nil
7
+    @title = nil
8
+    @class = ''
9
+    @width = ''
10
+    @height = ''
11
+
12
+    def initialize(tag_name, markup, tokens)
13
+      if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+\d+\s+\d+)?(\s+.+)?/i
14
+        @class = $1 || ''
15
+        @img = $2 + $3
16
+        if $5
17
+          @title = $5.strip
18
+        end
19
+        if $4 =~ /\s*(\d+)\s+(\d+)/
20
+          @width = $1
21
+          @height = $2
22
+        end
23
+      end
24
+      super
25
+    end
26
+
27
+    def render(context)
28
+      output = super
29
+      if @img
30
+        "<span class='#{('caption-wrapper ' + @class).rstrip}'>" +
31
+          "<img class='caption' src='#{@img}' width='#{@width}' height='#{@height}' title='#{@title}'>" +
32
+          "<span class='caption-text'>#{@title}</span>" +
33
+        "</span>"
34
+      else
35
+        "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [width height] [title text] %}"
36
+      end
37
+    end
38
+  end
39
+end
40
+
41
+Liquid::Template.register_tag('imgcap', Jekyll::CaptionImageTag)