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
37
38
39
# File 'lib/staticpress/site.rb', line 24

def each(&block)
  threads = []
  semaphore = Mutex.new

  CONTENT_TYPES.each do |content_type|
    threads << Thread.new do
      content_type.published.each do |content|
        semaphore.synchronize do
          block.call content
        end
      end
    end
  end

  threads.each &:join
end

#find_content_by_env(env) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/staticpress/site.rb', line 41

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



52
53
54
55
# File 'lib/staticpress/site.rb', line 52

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

#saveObject



57
58
59
60
61
# File 'lib/staticpress/site.rb', line 57

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