Browse code

1. Added image tag plugin 2. Removed figure tag plugin 3. Renamed custom_filters to octopress_filters 4. Added styles to support new image tag plugin

Brandon Mathis authored on 23/07/2011 at 04:23:50
Showing 5 changed files
... ...
@@ -42,14 +42,32 @@ article {
42 42
     font-size: 2.0em; font-style: italic;
43 43
     line-height: 1.3em;
44 44
   }
45
-  .entry-content {
46
-    img, video { max-width: 100%; height: auto; }
47
-    video {
48
-      width: 100%; display: block; margin-bottom: 1.5em;
49
-      padding: .8em; background: #fff; border: 1px solid #eee;
50
-      @include box-sizing(border-box);
45
+  img {
46
+    max-width: 100%;
47
+    border: .5em solid #fff;
48
+    @include border-radius(.3em);
49
+    @include box-shadow(rgba(#000, .15) 0 1px 4px);
50
+    @include box-sizing(border-box);
51
+    display: block;
52
+    margin: 0 auto 1.5em;
53
+    &.left {
54
+      float: left;
55
+      margin-right: 1.5em;
56
+    }
57
+    &.right {
58
+      float: right;
59
+      margin-left: 1.5em;
60
+    }
61
+    &.left, &.right {
62
+      margin-bottom: .8em;
51 63
     }
52 64
   }
65
+  img, video { max-width: 100%; height: auto; }
66
+  video {
67
+    width: 100%; display: block; margin-bottom: 1.5em;
68
+    padding: .8em; background: #fff; border: 1px solid #eee;
69
+    @include box-sizing(border-box);
70
+  }
53 71
   .flash-video {
54 72
     max-width: 100%;
55 73
     margin-bottom: 1.5em;
56 74
deleted file mode 100644
... ...
@@ -1,84 +0,0 @@
1
-#custom filters for Octopress
2
-
3
-module OctopressFilters
4
-  # Used on the blog index to split posts on the <!--more--> marker
5
-  def exerpt(input)
6
-    if input.index(/<!--\s*more\s*-->/i)
7
-      input.split(/<!--\s*more\s*-->/i)[0]
8
-    else
9
-      input
10
-    end
11
-  end
12
-
13
-  # Summary is used on the Archive pages to return the first block of content from a post.
14
-  def summary(input)
15
-    if input.index(/\n\n/)
16
-      input.split(/\n\n/)[0]
17
-    else
18
-      input
19
-    end
20
-  end
21
-
22
-  # Replaces relative urls with full urls
23
-  def expand_urls(input, url='')
24
-    url ||= '/'
25
-    input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do
26
-      $1+url+$3
27
-    end
28
-  end
29
-
30
-  # Removes trailing forward slash from a string for easily appending url segments
31
-  def strip_slash(input)
32
-    if input =~ /(.+)\/$|^\/$/
33
-      input = $1
34
-    end
35
-    input
36
-  end
37
-
38
-  # Returns a url without the protocol (http://)
39
-  def shorthand_url(input)
40
-    input.gsub /(https?:\/\/)(\S+)/ do
41
-      $2
42
-    end
43
-  end
44
-
45
-  # replaces primes with smartquotes using RubyPants
46
-  def smart_quotes(input)
47
-    require 'rubypants'
48
-    RubyPants.new(input).to_html
49
-  end
50
-
51
-  # Returns a title cased string based on John Gruber's title case http://daringfireball.net/2008/08/title_case_update
52
-  def titlecase(input)
53
-    input.titlecase
54
-  end
55
-
56
-  # Returns a datetime if the input is a string
57
-  def datetime(date)
58
-    if date.class == String
59
-      date = Time.parse(date)
60
-    end
61
-    date
62
-  end
63
-
64
-  # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
65
-  def ordinalize(date)
66
-    date = datetime(date)
67
-    "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}"
68
-  end
69
-
70
-  # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
71
-  def ordinal(number)
72
-    if (11..13).include?(number.to_i % 100)
73
-      "#{number}<span>th</span>"
74
-    else
75
-      case number.to_i % 10
76
-      when 1; "#{number}<span>st</span>"
77
-      when 2; "#{number}<span>nd</span>"
78
-      when 3; "#{number}<span>rd</span>"
79
-      else    "#{number}<span>th</span>"
80
-      end
81
-    end
82
-  end
83
-end
84
-Liquid::Template.register_filter OctopressFilters
85 1
deleted file mode 100644
... ...
@@ -1,69 +0,0 @@
1
-# Title: Simple Image Figure tag for Jekyll
2
-# Author: Brandon Mathis http://brandonmathis.com
3
-# Description: Easily output images in <figure> with an optional <figcaption> and class names.
4
-#
5
-# Syntax {% figure [class name(s)] url [caption text] %}
6
-#
7
-# Example:
8
-# {% figure left half http://site.com/images/ninja.png Ninja Attack! %}
9
-#
10
-# Output:
11
-# <figure class='left half'><img src="http://site.com/images/ninja.png"><figcaption>Ninja Attack!</figcaption></figure>
12
-#
13
-# Example 2 (image with caption)
14
-# {% figure /images/ninja.png Ninja Attack! %}
15
-#
16
-# Output:
17
-# <figure><img src="/images/ninja.png"><figcaption>Ninja Attack!</figcaption></figure>
18
-#
19
-# Example 3 (just an image with classes)
20
-# {% figure right /images/ninja.png %}
21
-#
22
-# Output:
23
-# <figure><img class="right" src="/images/ninja.png"></figure>
24
-#
25
-
26
-module Jekyll
27
-
28
-  class FigureImageTag < Liquid::Tag
29
-    ClassImgCaption = /(\S[\S\s]*)\s+(https?:\/\/|\/)(\S+)\s+(.+)/i
30
-    ClassImg = /(\S[\S\s]*)\s+(https?:\/\/|\/)(\S+)/i
31
-    ImgCaption = /^\s*(https?:\/\/|\/)(\S+)\s+(.+)/i
32
-    Img = /^\s*(https?:\/\/|\/)(\S+\s)/i
33
-
34
-    @img = nil
35
-    @caption = nil
36
-    @class = ''
37
-
38
-    def initialize(tag_name, markup, tokens)
39
-      if markup =~ ClassImgCaption
40
-        @class = $1
41
-        @img = $2 + $3
42
-        @caption = $4
43
-      elsif markup =~ ClassImg
44
-        @class = $1
45
-        @img = $2 + $3
46
-      elsif markup =~ ImgCaption
47
-        @img = $1 + $2
48
-        @caption = $3
49
-      elsif markup =~ Img
50
-        @img = $1 + $2
51
-      end
52
-      super
53
-    end
54
-
55
-    def render(context)
56
-      output = super
57
-      if @img
58
-        figure =  "<figure class='#{@class}'>"
59
-        figure += "<img src='#{@img}'>"
60
-        figure += "<figcaption>#{@caption}</figcaption>" if @caption
61
-        figure += "</figure>"
62
-      else
63
-        "Error processing input, expected syntax: {% figure [class name(s)] /url/to/image [caption] %}"
64
-      end
65
-    end
66
-  end
67
-end
68
-
69
-Liquid::Template.register_tag('figure', Jekyll::FigureImageTag)
70 1
new file mode 100644
... ...
@@ -0,0 +1,41 @@
0
+# Title: Simple Image tag for Jekyll
1
+# Author: Brandon Mathis http://brandonmathis.com
2
+# Description: Easily output images with optional class names and title/alt attributes
3
+#
4
+# Syntax {% image [class name(s)] url [title text] %}
5
+#
6
+# Example:
7
+# {% imaeg left half http://site.com/images/ninja.png Ninja Attack! %}
8
+#
9
+# Output:
10
+# <image class='left' src="http://site.com/images/ninja.png" title="Ninja Attack!" alt="Ninja Attack!">
11
+#
12
+
13
+module Jekyll
14
+
15
+  class ImageTag < Liquid::Tag
16
+    @img = nil
17
+    @title = nil
18
+    @class = ''
19
+
20
+    def initialize(tag_name, markup, tokens)
21
+      if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+.+)?/i
22
+        @class = $1
23
+        @img = $2 + $3
24
+        @title = $4
25
+      end
26
+      super
27
+    end
28
+
29
+    def render(context)
30
+      output = super
31
+      if @img
32
+        figure =  "<img class='#{@class}' src='#{@img}' alt='#{@title}' title='#{@title}'>"
33
+      else
34
+        "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [title text] %}"
35
+      end
36
+    end
37
+  end
38
+end
39
+
40
+Liquid::Template.register_tag('img', Jekyll::ImageTag)
0 41
new file mode 100644
... ...
@@ -0,0 +1,84 @@
0
+#custom filters for Octopress
1
+
2
+module OctopressFilters
3
+  # Used on the blog index to split posts on the <!--more--> marker
4
+  def exerpt(input)
5
+    if input.index(/<!--\s*more\s*-->/i)
6
+      input.split(/<!--\s*more\s*-->/i)[0]
7
+    else
8
+      input
9
+    end
10
+  end
11
+
12
+  # Summary is used on the Archive pages to return the first block of content from a post.
13
+  def summary(input)
14
+    if input.index(/\n\n/)
15
+      input.split(/\n\n/)[0]
16
+    else
17
+      input
18
+    end
19
+  end
20
+
21
+  # Replaces relative urls with full urls
22
+  def expand_urls(input, url='')
23
+    url ||= '/'
24
+    input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\"'>]+)/ do
25
+      $1+url+$3
26
+    end
27
+  end
28
+
29
+  # Removes trailing forward slash from a string for easily appending url segments
30
+  def strip_slash(input)
31
+    if input =~ /(.+)\/$|^\/$/
32
+      input = $1
33
+    end
34
+    input
35
+  end
36
+
37
+  # Returns a url without the protocol (http://)
38
+  def shorthand_url(input)
39
+    input.gsub /(https?:\/\/)(\S+)/ do
40
+      $2
41
+    end
42
+  end
43
+
44
+  # replaces primes with smartquotes using RubyPants
45
+  def smart_quotes(input)
46
+    require 'rubypants'
47
+    RubyPants.new(input).to_html
48
+  end
49
+
50
+  # Returns a title cased string based on John Gruber's title case http://daringfireball.net/2008/08/title_case_update
51
+  def titlecase(input)
52
+    input.titlecase
53
+  end
54
+
55
+  # Returns a datetime if the input is a string
56
+  def datetime(date)
57
+    if date.class == String
58
+      date = Time.parse(date)
59
+    end
60
+    date
61
+  end
62
+
63
+  # Returns an ordidinal date eg July 22 2007 -> July 22nd 2007
64
+  def ordinalize(date)
65
+    date = datetime(date)
66
+    "#{date.strftime('%b')} #{ordinal(date.strftime('%e').to_i)}, #{date.strftime('%Y')}"
67
+  end
68
+
69
+  # Returns an ordinal number. 13 -> 13th, 21 -> 21st etc.
70
+  def ordinal(number)
71
+    if (11..13).include?(number.to_i % 100)
72
+      "#{number}<span>th</span>"
73
+    else
74
+      case number.to_i % 10
75
+      when 1; "#{number}<span>st</span>"
76
+      when 2; "#{number}<span>nd</span>"
77
+      when 3; "#{number}<span>rd</span>"
78
+      else    "#{number}<span>th</span>"
79
+      end
80
+    end
81
+  end
82
+end
83
+Liquid::Template.register_filter OctopressFilters