Module: Middleman::Features::Webcomic

Defined in:
lib/middleman-webcomic/feature.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object Also known as: included



8
9
10
11
12
13
14
15
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/middleman-webcomic/feature.rb', line 8

def registered(app)
  puts "Webcomic v#{::Middleman::Webcomic::VERSION}"
      
  # Default settings:
  app.set :webcomic_images, "images/comics"
  app.set :webcomic_source, "comics"
  app.set :webcomic_source_images, "comics/images"
  app.set :webcomic_source_type, :markdown
  app.set :webcomic_uri, "comics"
  app.set :webcomic_template, "/comics/template.html"
  app.set :webcomic_domain, "http://MYSITE.dev" # ?
  
  # ???
  app.set :webcomic_enable_stories, false
  app.set :webcomic_story_uri, "story"
  app.set :webcomic_story_template, "/comics/story_template.html"

  app.set :webcomic_enable_tags, false
  app.set :webcomic_sort_by, :publish_date # or slug? and metadata
  app.set :webcomic_slug_field, :slug
  
  app.set :webcomic_include_comic_in_feed, true

  app.helpers ::Middleman::Features::Webcomic::Helpers
      
  app.after_configuration do
    comics, stories= ::Middleman::Webcomic.load_from( File.join(app.root, app.settings.webcomic_source), app )

    # puts comics.inspect

    comics.each do |comic|
      #puts "-> #{comic.filename} (#{comic.metadata.inspect})"
      src_path= File.join(app.root, app.settings.webcomic_source_images, comic.filename)
      tgt_path= File.join(app.views, app.settings.webcomic_images, comic.filename)
      
      unless File.exists? tgt_path
        if File.exists? src_path
          puts "Moving into place: #{comic.filename}"
          FileUtils.mkdir_p File.dirname(tgt_path), :verbose=>false
          FileUtils.cp src_path, tgt_path, :verbose=>false
        else
          puts "MISSING COMIC: #{comic.filename}"
        end
      end
      
      slug_field= app.settings.webcomic_slug_field
      if File.exists? tgt_path
        #puts "Building: /#{app.settings.webcomic_uri}/#{comic[slug_field]}.html"
        app.page "/#{app.settings.webcomic_uri}/#{comic[slug_field]}.html", :proxy=>app.settings.webcomic_template, :ignore=>true do
          @comic= comic
        end
      else
        puts "Skipping #{comic.filename} (#{comic[slug_field]})"
      end
    end
    
    if app.settings.webcomic_enable_stories
      stories.each do |story|
        app.page "/#{app.settings.webcomic_story_uri}/#{story.slug}.html", :proxy=>app.settings.webcomic_story_template, :ignore=>true do
          @story= story
        end
      end
    end
    
    app.data_content 'webcomic', {
      :strips=>comics,
      :stories=>stories
    }
  end
end