Class: Hyde::Project

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

Overview

project.ignored_files

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Project

Returns a new instance of Project.



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

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

  validate_version
  load_extensions

  require 'hyde/compass_support'
end

Instance Method Details

#build(&blk) ⇒ Object

Method: build (Hyde::Project) Builds.



152
153
154
155
156
157
158
159
# File 'lib/hyde/project.rb', line 152

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

#configObject

Method: config (Hyde::Project) Returns a Hyde::Config instance.



90
91
92
# File 'lib/hyde/project.rb', line 90

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

#config_fileObject

Method: config_file (Hyde::Project) Returns the configuration file for the project.



78
79
80
81
# File 'lib/hyde/project.rb', line 78

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)


83
84
85
# File 'lib/hyde/project.rb', line 83

def config_file?
  config_file
end

#filesObject

Method: files (Hyde::Project) Returns the site files for the project, free from the ignored files.



124
125
126
127
128
129
# File 'lib/hyde/project.rb', line 124

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

Method: ignored_files (Hyde::Project) Returns the files to be ignored for the project.



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/hyde/project.rb', line 134

def ignored_files
  specs  = [*config.ignore].map { |s| root(s) }
  specs << config_file

  # Ignore the standard files
  [:layouts, :extensions, :partials, :output].each do |aspect|
    specs << File.join(config.send(:"#{aspect}_path"), '**/*') if path(aspect) && path(aspect) != path(:site)
  end

  # Ignore dotfiles and hyde.conf by default
  specs += %w[.* _* *~ README* /hyde.conf /config.ru]

  specs.compact.map { |s| glob(s) }.flatten.uniq
end

#load_extensionsObject



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

def load_extensions
  path = path(:extensions)

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

#pagesObject

Method: pages (Hyde::Project) Returns the pages for the project.



117
118
119
# File 'lib/hyde/project.rb', line 117

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

#path(what, *a) ⇒ Object

Method: path (Hyde::Project) Returns the path for a certain aspect.

## Example

Hyde.project.path(:site)


101
102
103
104
105
# File 'lib/hyde/project.rb', line 101

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

Method: root (Hyde::Project) Returns the root path of the project.



110
111
112
# File 'lib/hyde/project.rb', line 110

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

#validate_versionObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hyde/project.rb', line 52

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