Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remove bit support

  • Loading branch information...
commit d8626f9789df0e71569733c1d65b954b243a886b 1 parent 8806587
Paul Stamatiou authored December 05, 2012
1  Rakefile
... ...
@@ -1,6 +1,7 @@
1 1
 require 'rubygems'
2 2
 require 'rake'
3 3
 require 'date'
  4
+require 'fastimage'
4 5
 
5 6
 #############################################################################
6 7
 #
11  bin/jekyll
@@ -17,6 +17,7 @@ HELP
17 17
 
18 18
 require 'optparse'
19 19
 require 'jekyll'
  20
+require 'fastimage'
20 21
 
21 22
 exec = {}
22 23
 options = {}
@@ -96,16 +97,6 @@ opts = OptionParser.new do |opts|
96 97
     end
97 98
   end
98 99
   
99  
-  opts.on("--limit_bits [MAX_BITS]", "Limit the number of bits to publish") do |limit_bits|
100  
-    begin
101  
-      options['limit_bits'] = limit_bits.to_i
102  
-      raise ArgumentError if options['limit_bits'] < 1
103  
-    rescue
104  
-      puts 'you must specify a number of bits by page bigger than 0'
105  
-      exit 0
106  
-    end
107  
-  end
108  
-
109 100
   opts.on("--url [URL]", "Set custom site.url") do |url|
110 101
     options['url'] = url
111 102
   end
2  jekyll.gemspec
@@ -56,7 +56,6 @@ Gem::Specification.new do |s|
56 56
     jekyll.gemspec
57 57
     lib/jekyll.rb
58 58
     lib/jekyll/albino.rb
59  
-    lib/jekyll/bit.rb
60 59
     lib/jekyll/converter.rb
61 60
     lib/jekyll/converters/identity.rb
62 61
     lib/jekyll/converters/markdown.rb
@@ -79,6 +78,7 @@ Gem::Specification.new do |s|
79 78
     lib/jekyll/migrators/wordpress.rb
80 79
     lib/jekyll/page.rb
81 80
     lib/jekyll/plugin.rb
  81
+    lib/jekyll/photo.rb
82 82
     lib/jekyll/post.rb
83 83
     lib/jekyll/site.rb
84 84
     lib/jekyll/static_file.rb
2  lib/jekyll.rb
@@ -23,6 +23,7 @@ def require_all(path)
23 23
 # 3rd party
24 24
 require 'liquid'
25 25
 require 'maruku'
  26
+require 'fastimage'
26 27
 
27 28
 # internal requires
28 29
 require 'jekyll/core_ext'
@@ -31,7 +32,6 @@ def require_all(path)
31 32
 require 'jekyll/layout'
32 33
 require 'jekyll/page'
33 34
 require 'jekyll/post'
34  
-require 'jekyll/bit'
35 35
 require 'jekyll/photo'
36 36
 require 'jekyll/filters'
37 37
 require 'jekyll/albino'
253  lib/jekyll/bit.rb
... ...
@@ -1,253 +0,0 @@
1  
-module Jekyll
2  
-
3  
-  class Bit
4  
-    include Comparable
5  
-    include Convertible
6  
-
7  
-    class << self
8  
-      attr_accessor :lsi
9  
-    end
10  
-
11  
-    MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)(\.[^.]+)$/
12  
-
13  
-    # Bit name validator. Bit filenames must be like:
14  
-    #   2008-11-05-my-awesome-bit.textile
15  
-    #
16  
-    # Returns <Bool>
17  
-    def self.valid?(name)
18  
-      name =~ MATCHER
19  
-    end
20  
-
21  
-    attr_accessor :site
22  
-    attr_accessor :data, :content, :output, :ext
23  
-    attr_accessor :date, :slug, :published, :tags, :categories
24  
-
25  
-    # Initialize this Bit instance.
26  
-    #   +site+ is the Site
27  
-    #   +base+ is the String path to the dir containing the bit file
28  
-    #   +name+ is the String filename of the bit file
29  
-    #   +categories+ is an Array of Strings for the categories for this bit
30  
-    #
31  
-    # Returns <Bit>
32  
-    def initialize(site, source, dir, name)
33  
-      @site = site
34  
-      @base = File.join(source, dir, '_bits')
35  
-      @name = name
36  
-
37  
-      self.categories = dir.split('/').reject { |x| x.empty? }
38  
-      self.process(name)
39  
-      self.read_yaml(@base, name)
40  
-
41  
-      #If we've added a date and time to the yaml, use that instead of the filename date
42  
-      #Means we'll sort correctly.
43  
-      if self.data.has_key?('date')
44  
-        # ensure Time via to_s and reparse
45  
-        self.date = Time.parse(self.data["date"].to_s)
46  
-      end
47  
-
48  
-      if self.data.has_key?('published') && self.data['published'] == false
49  
-        self.published = false
50  
-      else
51  
-        self.published = true
52  
-      end
53  
-
54  
-      self.tags = self.data.pluralized_array("tag", "tags")
55  
-
56  
-      if self.categories.empty?
57  
-        self.categories = self.data.pluralized_array('category', 'categories')
58  
-      end
59  
-    end
60  
-
61  
-    # Spaceship is based on Bit#date, slug
62  
-    #
63  
-    # Returns -1, 0, 1
64  
-    def <=>(other)
65  
-      cmp = self.date <=> other.date
66  
-      if 0 == cmp
67  
-       cmp = self.slug <=> other.slug
68  
-      end
69  
-      return cmp
70  
-    end
71  
-
72  
-    # Extract information from the bit filename
73  
-    #   +name+ is the String filename of the bit file
74  
-    #
75  
-    # Returns nothing
76  
-    def process(name)
77  
-      m, cats, date, slug, ext = *name.match(MATCHER)
78  
-      self.date = Time.parse(date)
79  
-      self.slug = slug
80  
-      self.ext = ext
81  
-    end
82  
-
83  
-    # The generated directory into which the bit will be placed
84  
-    # upon generation. This is derived from the permalink or, if
85  
-    # permalink is absent, set to the default date
86  
-    # e.g. "/2008/11/05/" if the permalink style is :date, otherwise nothing
87  
-    #
88  
-    # Returns <String>
89  
-    def dir
90  
-      File.dirname(generated_path)
91  
-    end
92  
-
93  
-    # The full path and filename of the bit.
94  
-    # Defined in the YAML of the bit body
95  
-    # (Optional)
96  
-    #
97  
-    # Returns <String>
98  
-    def permalink
99  
-      self.data && self.data['permalink']
100  
-    end
101  
-
102  
-    def template
103  
-      case self.site.permalink_style
104  
-      when :pretty
105  
-        "/:categories/:year/:month/:day/:title/"
106  
-      when :none
107  
-        "/:categories/:title.html"
108  
-      when :date
109  
-        "/:categories/:year/:month/:day/:title.html"
110  
-      else
111  
-        self.site.permalink_style.to_s
112  
-      end
113  
-    end
114  
-
115  
-    # The generated relative url of this bit
116  
-    # e.g. /2008/11/05/my-awesome-bit.html
117  
-    #
118  
-    # Returns <String>
119  
-    def generated_path
120  
-      return permalink if permalink
121  
-
122  
-      @generated_path ||= {
123  
-        "year"       => date.strftime("%Y"),
124  
-        "month"      => date.strftime("%m"),
125  
-        "day"        => date.strftime("%d"),
126  
-        "title"      => CGI.escape(slug),
127  
-        "i_day"      => date.strftime("%d").to_i.to_s,
128  
-        "i_month"    => date.strftime("%m").to_i.to_s,
129  
-        "categories" => categories.join('/'),
130  
-        "output_ext" => self.output_ext
131  
-      }.inject(template) { |result, token|
132  
-        result.gsub(/:#{Regexp.escape token.first}/, token.last)
133  
-      }.gsub(/\/\//, "/")
134  
-    end
135  
-    
136  
-    # The generated relative url of this bit
137  
-    # e.g. /2008/11/05/my-awesome-bit
138  
-    #
139  
-    # Returns <String>
140  
-    def url
141  
-      site.config['multiviews'] ? generated_path.sub(/\.html$/, '') : generated_path
142  
-    end
143  
-
144  
-    # The UID for this bit (useful in feeds)
145  
-    # e.g. /2008/11/05/my-awesome-bit
146  
-    #
147  
-    # Returns <String>
148  
-    def id
149  
-      File.join(self.dir, self.slug)
150  
-    end
151  
-
152  
-    # Calculate related bits.
153  
-    #
154  
-    # Returns [<Bit>]
155  
-    def related_bits(bits)
156  
-      return [] unless bits.size > 1
157  
-
158  
-      if self.site.lsi
159  
-        self.class.lsi ||= begin
160  
-          puts "Running the classifier... this could take a while."
161  
-          lsi = Classifier::LSI.new
162  
-          bits.each { |x| $stdout.print(".");$stdout.flush;lsi.add_item(x) }
163  
-          puts ""
164  
-          lsi
165  
-        end
166  
-
167  
-        related = self.class.lsi.find_related(self.content, 11)
168  
-        related - [self]
169  
-      else
170  
-        (bits - [self])[0..9]
171  
-      end
172  
-    end
173  
-
174  
-    # Add any necessary layouts to this bit
175  
-    #   +layouts+ is a Hash of {"name" => "layout"}
176  
-    #   +site_payload+ is the site payload hash
177  
-    #
178  
-    # Returns nothing
179  
-    def render(layouts, site_payload)
180  
-      # construct payload
181  
-      payload = {
182  
-        "site" => { "related_bits" => related_bits(site_payload["site"]["bits"]) },
183  
-        "page" => self.to_liquid
184  
-      }.deep_merge(site_payload)
185  
-
186  
-      do_layout(payload, layouts)
187  
-    end
188  
-    
189  
-    # Obtain destination path.
190  
-    #   +dest+ is the String path to the destination dir
191  
-    #
192  
-    # Returns destination file path.
193  
-    def destination(dest)
194  
-      # The url needs to be unescaped in order to preserve the correct filename
195  
-      path = File.join(dest, CGI.unescape(self.generated_path))
196  
-      path = File.join(path, "index.html") if template[/\.html$/].nil?
197  
-      path
198  
-    end
199  
-
200  
-    # Write the generated bit file to the destination directory.
201  
-    #   +dest+ is the String path to the destination dir
202  
-    #
203  
-    # Returns nothing
204  
-    def write(dest)
205  
-      path = destination(dest)
206  
-      FileUtils.mkdir_p(File.dirname(path))
207  
-      File.open(path, 'w') do |f|
208  
-        f.write(self.output)
209  
-      end
210  
-    end
211  
-
212  
-    # Convert this bit into a Hash for use in Liquid templates.
213  
-    #
214  
-    # Returns <Hash>
215  
-    def to_liquid
216  
-      self.data.deep_merge({
217  
-        "title"      => self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' '),
218  
-        "url"        => self.url,
219  
-        "date"       => self.date,
220  
-        "id"         => self.id,
221  
-        "categories" => self.categories,
222  
-        "folded" => (self.content.match("<!--more-->") ? true : false),
223  
-        "next"       => self.next,
224  
-        "previous"   => self.previous,
225  
-        "tags"       => self.tags,
226  
-        "content"    => self.content })
227  
-    end
228  
-
229  
-    def inspect
230  
-      "<Bit: #{self.id}>"
231  
-    end
232  
-
233  
-    def next
234  
-      pos = self.site.bits.index(self)
235  
-
236  
-      if pos && pos < self.site.bits.length-1
237  
-        self.site.bits[pos+1]
238  
-      else
239  
-        nil
240  
-      end
241  
-    end
242  
-
243  
-    def previous
244  
-      pos = self.site.bits.index(self)
245  
-      if pos && pos > 0
246  
-        self.site.bits[pos-1]
247  
-      else
248  
-        nil
249  
-      end
250  
-    end
251  
-  end
252  
-
253  
-end
4  lib/jekyll/photo.rb
@@ -149,9 +149,9 @@ def id
149 149
       File.join(self.dir, self.slug)
150 150
     end
151 151
 
152  
-    # Calculate related bits.
  152
+    # Calculate related photos.
153 153
     #
154  
-    # Returns [<Bit>]
  154
+    # Returns [<Photo>]
155 155
     def related_photos(photos)
156 156
       return [] unless photos.size > 1
157 157
 
78  lib/jekyll/site.rb
... ...
@@ -1,8 +1,8 @@
1 1
 module Jekyll
2 2
 
3 3
   class Site
4  
-    attr_accessor :config, :layouts, :posts, :pages, :static_files, :bits, :photos,
5  
-                  :categories, :exclude, :source, :dest, :lsi, :pygments, :limit_bits,
  4
+    attr_accessor :config, :layouts, :posts, :pages, :static_files, :photos,
  5
+                  :categories, :exclude, :source, :dest, :lsi, :pygments,
6 6
                   :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, :collated
7 7
 
8 8
     attr_accessor :converters, :generators
@@ -24,7 +24,6 @@ def initialize(config)
24 24
       self.exclude         = config['exclude'] || []
25 25
       self.future          = config['future']
26 26
       self.limit_posts     = config['limit_posts'] || nil
27  
-      self.limit_bits      = config['limit_bits'] || nil
28 27
 
29 28
       self.reset
30 29
       self.setup
@@ -39,14 +38,12 @@ def reset
39 38
       self.layouts         = {}
40 39
       self.posts           = []
41 40
       self.pages           = []
42  
-      self.bits            = []
43 41
       self.photos          = []
44 42
       self.static_files    = []
45 43
       self.categories      = Hash.new { |hash, key| hash[key] = [] }
46 44
       self.tags            = Hash.new { |hash, key| hash[key] = [] }
47 45
       self.collated        = {}
48 46
       raise ArgumentError, "Limit posts must be nil or >= 1" if !self.limit_posts.nil? && self.limit_posts < 1
49  
-      raise ArgumentError, "Limit bits must be nil or >= 1" if !self.limit_bits.nil? && self.limit_bits < 1
50 47
     end
51 48
 
52 49
     def setup
@@ -137,34 +134,6 @@ def read_posts(dir)
137 134
       self.posts = self.posts[-limit_posts, limit_posts] if limit_posts
138 135
     end
139 136
     
140  
-    # Read all the files in <source>/<dir>/_bits and create a new Bit
141  
-    # object with each one.
142  
-    #
143  
-    # Returns nothing
144  
-    def read_bits(dir)
145  
-      base = File.join(self.source, dir, '_bits')
146  
-      return unless File.exists?(base)
147  
-      entries = Dir.chdir(base) { filter_entries(Dir['**/*']) }
148  
-
149  
-      # first pass processes, but does not yet render post content
150  
-      entries.each do |f|
151  
-        if Bit.valid?(f)
152  
-          bit = Bit.new(self, self.source, dir, f)
153  
-
154  
-          if bit.published && (self.future || bit.date <= self.time)
155  
-            self.bits << bit
156  
-            bit.categories.each { |c| self.categories[c] << bit }
157  
-            bit.tags.each { |c| self.tags[c] << bit }
158  
-          end
159  
-        end
160  
-      end
161  
-
162  
-      self.bits.sort!
163  
-
164  
-      # limit the posts if :limit_bits option is set
165  
-      self.bits = self.bits[-limit_bits, limit_bits] if limit_bits
166  
-    end
167  
-    
168 137
     # Read all the files in <source>/<dir>/_photos and create a new photo
169 138
     # object with each one.
170 139
     #
@@ -218,10 +187,6 @@ def render
218 187
         post.render(self.layouts, site_payload)
219 188
       end
220 189
       
221  
-      self.bits.each do |bit|
222  
-        bit.render(self.layouts, site_payload)
223  
-      end
224  
-      
225 190
       self.photos.each do |photo|
226 191
         photo.render(self.layouts, site_payload)
227 192
       end
@@ -251,9 +216,6 @@ def cleanup
251 216
       self.posts.each do |post|
252 217
         files << post.destination(self.dest)
253 218
       end
254  
-      self.bits.each do |bit|
255  
-        files << bit.destination(self.dest)
256  
-      end
257 219
       self.photos.each do |photo|
258 220
         files << photo.destination(self.dest)
259 221
       end
@@ -272,16 +234,13 @@ def cleanup
272 234
       FileUtils.rm_rf(obsolete_files)
273 235
     end
274 236
 
275  
-    # Write static files, pages, posts and bits
  237
+    # Write static files, pages, posts and photos
276 238
     #
277 239
     # Returns nothing
278 240
     def write
279 241
       self.posts.each do |post|
280 242
         post.write(self.dest)
281 243
       end
282  
-      self.bits.each do |bit|
283  
-        bit.write(self.dest)
284  
-      end
285 244
       self.photos.each do |photo|
286 245
         photo.write(self.dest)
287 246
       end
@@ -334,7 +293,6 @@ def read_directories(dir = '')
334 293
       entries = filter_entries(Dir.entries(base))
335 294
 
336 295
       self.read_posts(dir)
337  
-      self.read_bits(dir)
338 296
       self.read_photos(dir)
339 297
 
340 298
       entries.each do |f|
@@ -369,27 +327,6 @@ def post_attr_hash(post_attr)
369 327
       return hash
370 328
     end
371 329
     
372  
-    # Constructs a hash map of Bits indexed by the specified Bit attribute
373  
-    #
374  
-    # Returns {bit_attr => [<Bit>]}
375  
-    def bit_attr_hash(bit_attr)
376  
-      # Build a hash map based on the specified bit attribute ( bit attr => array of bits )
377  
-      # then sort each array in reverse order
378  
-      hash = Hash.new { |hash, key| hash[key] = Array.new }
379  
-      self.bits.each { |b| b.send(bit_attr.to_sym).each { |t| hash[t] << b } }
380  
-      hash.values.map { |sortme| sortme.sort! { |x, y| y <=> x} }
381  
-      return hash
382  
-    end
383  
-
384  
-    def post_bit_attr_hash(content_attr)
385  
-      hash = Hash.new { |hash, key| hash[key] = Array.new }
386  
-      self.posts.each { |p| p.send(content_attr.to_sym).each { |t| hash[t] << p } }
387  
-      self.bits.each { |b| b.send(content_attr.to_sym).each { |t| hash[t] << b } }
388  
-      self.photos.each  { |ph| ph.send(content_attr.to_sym).each { |t| hash[t] << ph } }
389  
-      hash.values.map { |sortme| sortme.sort! { |x, y| y <=> x} }
390  
-      return hash
391  
-    end
392  
-
393 330
     # The Hash payload containing site-wide data
394 331
     #
395 332
     # Returns {"site" => {"time" => <Time>,
@@ -401,17 +338,12 @@ def site_payload
401 338
       {"site" => self.config.merge({
402 339
           "time"            => self.time,
403 340
           "posts"           => self.posts.sort { |a,b| b <=> a },
404  
-          "bits"            => self.bits.sort { |a,b| b <=> a },
405 341
           "photos"          => self.photos.sort { |a,b| b <=> a },
406 342
           "collated_posts"  => self.collated,
407 343
           "pages"           => self.pages,
408 344
           "html_pages"      => self.pages.reject { |page| !page.html? },
409  
-          #"bit_tags"        => bit_attr_hash('tags'),
410  
-          #"bit_categories"  => bit_attr_hash('categories'),
411  
-          "tags"            => post_bit_attr_hash('tags'),
412  
-          "categories"      => post_bit_attr_hash('categories')})}
413  
-          #"categories"      => post_attr_hash('categories'),
414  
-          #"tags"            => post_attr_hash('tags')})}
  345
+          "categories"      => post_attr_hash('categories'),
  346
+          "tags"            => post_attr_hash('tags')})}
415 347
     end
416 348
 
417 349
     # Filter out any files/directories that are hidden or backup files (start

0 notes on commit d8626f9

Please sign in to comment.
Something went wrong with that request. Please try again.