Class: Hyde::Project
- Inherits:
-
Object
- Object
- Hyde::Project
- Defined in:
- lib/hyde/project.rb
Instance Method Summary collapse
- #build(&blk) ⇒ Object
- #config ⇒ Object
- #config_file ⇒ Object
- #config_file? ⇒ Boolean
- #files ⇒ Object
- #ignored_files ⇒ Object
-
#initialize(root = Dir.pwd) ⇒ Project
constructor
A new instance of Project.
- #load_extensions ⇒ Object
- #pages ⇒ Object
-
#path(what, *a) ⇒ Object
Returns the path for a certain aspect.
- #root(*args) ⇒ Object
- #validate_version ⇒ Object
Constructor Details
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 |
#config ⇒ Object
40 41 42 |
# File 'lib/hyde/project.rb', line 40 def config @config ||= Config.load(config_file) end |
#config_file ⇒ Object
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
36 37 38 |
# File 'lib/hyde/project.rb', line 36 def config_file? config_file end |
#files ⇒ Object
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.(f) } files - ignored_files end |
#ignored_files ⇒ Object
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_extensions ⇒ Object
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 |
#pages ⇒ Object
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.
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_version ⇒ Object
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 |