Class: Hyde::Project
- Inherits:
-
Object
- Object
- Hyde::Project
- Defined in:
- lib/hyde/project.rb
Overview
project.ignored_files
Instance Method Summary collapse
-
#build(&blk) ⇒ Object
Method: build (Hyde::Project) Builds.
-
#config ⇒ Object
Method: config (Hyde::Project) Returns a Hyde::Config instance.
-
#config_file ⇒ Object
Method: config_file (Hyde::Project) Returns the configuration file for the project.
- #config_file? ⇒ Boolean
-
#files ⇒ Object
Method: files (Hyde::Project) Returns the site files for the project, free from the ignored files.
-
#ignored_files ⇒ Object
Method: ignored_files (Hyde::Project) Returns the files to be ignored for the project.
-
#initialize(root = Dir.pwd) ⇒ Project
constructor
A new instance of Project.
- #load_extensions ⇒ Object
-
#pages ⇒ Object
Method: pages (Hyde::Project) Returns the pages for the project.
-
#path(what, *a) ⇒ Object
Method: path (Hyde::Project) Returns the path for a certain aspect.
-
#root(*args) ⇒ Object
Method: root (Hyde::Project) Returns the root path of the project.
- #validate_version ⇒ Object
Constructor Details
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 |
#config ⇒ Object
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_file ⇒ Object
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
83 84 85 |
# File 'lib/hyde/project.rb', line 83 def config_file? config_file end |
#files ⇒ Object
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.(f) } files - ignored_files end |
#ignored_files ⇒ Object
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_extensions ⇒ Object
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 |
#pages ⇒ Object
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
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_version ⇒ Object
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 |