Module: Middleman::Webcomic

Defined in:
lib/middleman-webcomic/data.rb,
lib/middleman-webcomic/pager.rb,
lib/middleman-webcomic/version.rb,
lib/middleman-webcomic/mock_app.rb,
lib/middleman-webcomic/template.rb

Defined Under Namespace

Classes: Comic, MockApp, Pager, Story, Template

Constant Summary collapse

VERSION =
"0.5.1"

Class Method Summary collapse

Class Method Details

.load_from(path, app) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/middleman-webcomic/data.rb', line 16

def self.load_from(path, app)
  all= []
  Dir["#{path}/*.comic*"].each do |filename| # Hardcoded for markdown... For now
    comic = Comic.new(filename, app)
    #puts comic.pub_date.inspect
    all << comic if comic.publishable?
  end

  if app.settings.webcomic_sort_by == :publish_date
    all.sort! {|x,y| y.pub_date <=> x.pub_date }
  else
    fld= app.settings.webcomic_sort_by
    all.sort! {|x,y| y[fld] <=> x[fld] }
  end

  # Update all the position info...
  cl= all.length
  all.each_with_index do |comic, i|
    comic[:position]= (cl - i)
    comic[:index]= i
    comic.first= all[-1]
    comic.last= all[0]
    comic.next= i > 0  ? all[i - 1] :  nil
    comic.prev= i < (cl - 1) ? all[i + 1] : nil
    if app.settings.webcomic_enable_stories and comic.story 
      Story.find_or_create_for comic
    end
  end

  stories= Story.all
  stories.sort! {|x,y| y.pub_date <=> x.pub_date }
  sl= stories.length
  stories.each_with_index do |story, i|
    story.position= (sl - i)
    # puts "##{story.position} - #{story.title}(#{story.slug}): #{story.comics.length}"
  end

  [all, stories]
end