Class: Stic::Site
- Inherits:
-
Object
- Object
- Stic::Site
- Defined in:
- lib/stic/site.rb
Overview
Attributes collapse
-
#config ⇒ Config
readonly
The project’s configuration object.
-
#generators ⇒ Array<Generator>
readonly
The list of initialized Generators.
-
#source ⇒ Path
readonly
The project’s source path.
-
#target ⇒ Path
readonly
The project’s target path.
Construction collapse
-
#initialize(source, config) ⇒ Site
constructor
Initializes new Site object.
Accessors collapse
-
#blobs(opts = {}) ⇒ Object
Return list of Blobs.
-
#layout(name) ⇒ Object
Get layout with given name.
Actions collapse
-
.generators ⇒ Object
Return list of available generator classes.
-
.lookup(dir = Path.getwd) ⇒ Object
Try to find a stic site in given directory or above.
-
#<<(blob) ⇒ Object
Add new Blob to site.
-
#cleanup ⇒ Self
Cleanup target directory.
-
#run {|generator| ... } ⇒ Self
Run all registered and initialized Generators.
-
#write {|blob| ... } ⇒ Self
Write all added Blobs to their destination.
Constructor Details
#initialize(source, config) ⇒ Site
Initializes new Stic::Site object.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stic/site.rb', line 53 def initialize(source, config) @config = config @source = Path.new source @target = Path.new(source).join('site'). @blobs = [] @layouts = [] @generators = self.class.generators.map do |generator_class| generator_class.new self, config['generators'] end end |
Instance Attribute Details
#config ⇒ Config (readonly)
The project’s configuration object. Will be initialized with the values loaded from configuration file found in project’s source directory.
35 36 37 |
# File 'lib/stic/site.rb', line 35 def config @config end |
#generators ⇒ Array<Generator> (readonly)
The list of initialized Generators. They will be initialized within the #initialize method.
42 43 44 |
# File 'lib/stic/site.rb', line 42 def generators @generators end |
#source ⇒ Path (readonly)
The project’s source path.
22 23 24 |
# File 'lib/stic/site.rb', line 22 def source @source end |
#target ⇒ Path (readonly)
The project’s target path.
28 29 30 |
# File 'lib/stic/site.rb', line 28 def target @target end |
Class Method Details
.generators ⇒ Object
Return list of available generator classes.
169 170 171 |
# File 'lib/stic/site.rb', line 169 def generators @generators ||= [] end |
.lookup(dir = Path.getwd) ⇒ Object
Try to find a stic site in given directory or above. If no directory is given the current working directory will be used.
163 164 165 166 |
# File 'lib/stic/site.rb', line 163 def lookup(dir = Path.getwd) file = Path.new(dir).lookup(/^stic.ya?ml$/) file ? new(file.dirname, Stic::Config.load(file)) : nil end |
Instance Method Details
#<<(blob) ⇒ Object
154 155 156 |
# File 'lib/stic/site.rb', line 154 def <<(blob) blobs << blob end |
#blobs(opts = {}) ⇒ Object
82 83 84 85 |
# File 'lib/stic/site.rb', line 82 def blobs(opts = {}) return @blobs if opts[:type].nil? @blobs.select{|blob| blob.class <= opts[:type] } end |
#cleanup ⇒ Self
Cleanup target directory. That will remove all files and directories not referenced by any Blob.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/stic/site.rb', line 132 def cleanup paths = blobs.map(&:target_path) # Cleanup not longer referenced files target.glob('**/*').each do |path| if path.file? && !paths.include?(path) path.unlink elsif path.directory? && !paths.any?{|p| p.path.starts_with? path.to_s } path.rm_rf end end self end |
#layout(name) ⇒ Object
Get layout with given name.
69 70 71 |
# File 'lib/stic/site.rb', line 69 def layout(name) @layouts.fetch(name) end |