Class: Proton::Project
- Inherits:
-
Object
- Object
- Proton::Project
- Defined in:
- lib/proton/project.rb
Overview
project.ignored_files
Instance Method Summary collapse
-
#build(&blk) ⇒ Object
Method: build (Proton::Project) Builds.
-
#config ⇒ Object
Method: config (Proton::Project) Returns a Proton::Config instance.
-
#config_file ⇒ Object
Method: config_file (Proton::Project) Returns the configuration file for the project.
- #config_file? ⇒ Boolean
-
#files ⇒ Object
Method: files (Proton::Project) Returns the site files for the project, free from the ignored files.
-
#ignored_files ⇒ Object
Method: ignored_files (Proton::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 (Proton::Project) Returns the pages for the project.
-
#path(what, *a) ⇒ Object
Method: path (Proton::Project) Returns the path for a certain aspect.
-
#root(*args) ⇒ Object
Method: root (Proton::Project) Returns the root path of the project.
- #validate_version ⇒ Object
Constructor Details
Instance Method Details
#build(&blk) ⇒ Object
Method: build (Proton::Project) Builds.
153 154 155 156 157 158 159 160 |
# File 'lib/proton/project.rb', line 153 def build(&blk) pages.each do |page| yield page page.write end ensure build_cleanup end |
#config ⇒ Object
Method: config (Proton::Project) Returns a Proton::Config instance.
90 91 92 |
# File 'lib/proton/project.rb', line 90 def config @config ||= Config.load(config_file) end |
#config_file ⇒ Object
Method: config_file (Proton::Project) Returns the configuration file for the project.
78 79 80 81 |
# File 'lib/proton/project.rb', line 78 def config_file try = lambda { |path| p = root(path); p if File.file?(p) } Proton::CONFIG_FILES.inject(nil) { |acc, file| acc ||= try[file] } end |
#config_file? ⇒ Boolean
83 84 85 |
# File 'lib/proton/project.rb', line 83 def config_file? config_file end |
#files ⇒ Object
Method: files (Proton::Project) Returns the site files for the project, free from the ignored files.
124 125 126 127 128 129 |
# File 'lib/proton/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 (Proton::Project) Returns the files to be ignored for the project.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/proton/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 files by default specs += %w[.* _* *~ README* /config.ru Gemfile Gemfile.lock] specs += Proton::CONFIG_FILES.map { |s| "/#{s}" } specs.compact.map { |s| glob(s) }.flatten.uniq end |
#load_extensions ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/proton/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 (Proton::Project) Returns the pages for the project.
117 118 119 |
# File 'lib/proton/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/proton/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 (Proton::Project) Returns the root path of the project.
110 111 112 |
# File 'lib/proton/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/proton/project.rb', line 52 def validate_version return unless config_file? req = config.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[Proton.version] raise VersionError, "You will need Proton version >= #{req} for this project." end end |