Class: Staticpress::Site

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Helpers
Defined in:
lib/staticpress/site.rb

Constant Summary collapse

CONTENT_TYPES =

ordered by priority

[
  Staticpress::Content::Page,
  Staticpress::Content::Post,
  Staticpress::Content::Index,
  Staticpress::Content::Category,
  Staticpress::Content::Tag,
  Staticpress::Content::Theme
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#config, #extensionless_basename, #extensionless_path, #hash_from_array, #hash_from_match_data, #paginate, #settings, #spider_map, #titleize

Constructor Details

#initializeSite

Returns a new instance of Site.



20
21
22
# File 'lib/staticpress/site.rb', line 20

def initialize
  @directory = Staticpress.blog_path + config.source_path
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



18
19
20
# File 'lib/staticpress/site.rb', line 18

def directory
  @directory
end

Instance Method Details

#each(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/staticpress/site.rb', line 24

def each(&block)
  semaphore = Mutex.new

  CONTENT_TYPES.map do |content_type|
    Thread.new do
      content_type.published.each do |content|
        semaphore.synchronize do
          block.call content
        end
      end
    end
  end.each(&:join)
end

#find_content_by_env(env) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/staticpress/site.rb', line 38

def find_content_by_env(env)
  catch :content do
    CONTENT_TYPES.detect do |content_type|
      content = content_type.find_by_url_path env['REQUEST_PATH']
      throw :content, content if content && content.exist?
    end

    nil
  end
end

#metaObject



49
50
51
52
# File 'lib/staticpress/site.rb', line 49

def meta
  # or something...
  inject(Staticpress::Metadata.new) { |meta, content| meta << content.meta }
end

#saveObject



54
55
56
57
58
# File 'lib/staticpress/site.rb', line 54

def save
  destination = Staticpress.blog_path + config.destination_path
  FileUtils.rm_r destination if destination.directory?
  each &:save
end