Class: Hyde::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/hyde/project.rb

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Project

Returns a new instance of Project.



3
4
5
6
7
8
9
# File 'lib/hyde/project.rb', line 3

def initialize(root=Dir.pwd)
  @root = root
  Hyde.project = self

  validate_version
  load_extensions
end

Instance Method Details

#build(&blk) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/hyde/project.rb', line 76

def build(&blk)
  pages.each do |page|
    yield page
    page.write
  end
ensure
  build_cleanup
end

#configObject



40
41
42
# File 'lib/hyde/project.rb', line 40

def config
  @config ||= Config.load(config_file)
end

#config_fileObject



31
32
33
34
# File 'lib/hyde/project.rb', line 31

def config_file
  try = lambda { |path| p = root(path); p if File.file?(p) }
  try['hyde.conf'] || try['.hyderc']
end

#config_file?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/hyde/project.rb', line 36

def config_file?
  config_file
end

#filesObject



60
61
62
63
64
65
# File 'lib/hyde/project.rb', line 60

def files
  files = Dir[File.join(path(:site), '**', '*')]
  files = files.select { |f| File.file?(f) }
  files = files.map { |f| File.expand_path(f) }
  files - ignored_files
end

#ignored_filesObject



67
68
69
70
71
72
73
74
# File 'lib/hyde/project.rb', line 67

def ignored_files
  specs  = [*config.ignore].map { |s| root(s) }
  specs << config_file
  [:layouts, :extensions, :partials, :output].each do |aspect|
    specs << path(aspect, '**/*') if path(aspect) && path(aspect) != path(:site)
  end
  specs.compact.map { |s| Dir[s] }.flatten.uniq
end

#load_extensionsObject



26
27
28
29
# File 'lib/hyde/project.rb', line 26

def load_extensions
  path = path(:extensions)
  Dir[path(:extensions, '*', '*.rb')].each { |f| require f }  if path
end

#pagesObject



56
57
58
# File 'lib/hyde/project.rb', line 56

def pages
  files.map { |f| Page[f, self] }.compact
end

#path(what, *a) ⇒ Object

Returns the path for a certain aspect.

Examples:

path(:site)



46
47
48
49
50
# File 'lib/hyde/project.rb', line 46

def path(what, *a)
  return nil unless [:output, :site, :layouts, :extensions, :partials].include?(what)
  path = config.send(:"#{what}_path")
  root path, *a  if path
end

#root(*args) ⇒ Object



52
53
54
# File 'lib/hyde/project.rb', line 52

def root(*args)
  File.join @root, *(args.compact)
end

#validate_versionObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hyde/project.rb', line 11

def validate_version
  return unless config_file?
  req = config.hyde_requirement.to_s

  v = lambda { |version| Gem::Version.new version }

  if req.empty?
    # pass
  elsif v[req] < v["0.1"]
    raise LegacyError, "This is a legacy project"
  elsif v[req] > v[Hyde.version]
    raise VersionError, "You will need Hyde version >= #{req} for this project."
  end
end