Class: Zwite::Site
Instance Attribute Summary collapse
-
#apps ⇒ Object
Returns the value of attribute apps.
-
#apps_path ⇒ Object
Returns the value of attribute apps_path.
-
#cache_path ⇒ Object
Returns the value of attribute cache_path.
-
#config ⇒ Object
Returns the value of attribute config.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#liquid_context ⇒ Object
Returns the value of attribute liquid_context.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#path ⇒ Object
Properties.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
- #build ⇒ Object
- #files_changed? ⇒ Boolean
- #generate ⇒ Object
-
#initialize(path) ⇒ Site
constructor
Initialization.
-
#load ⇒ Object
Actions.
- #preprocess ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(path) ⇒ Site
Initialization
64 65 66 67 68 69 70 71 |
# File 'lib/zwite/core/site.rb', line 64 def initialize(path) self.path = path self.config_path = self.path + "config.yml" self.apps_path = self.path + "apps" self.output_path = self.path + "public" self.cache_path = self.path + ".cache" self.load end |
Instance Attribute Details
#apps ⇒ Object
Returns the value of attribute apps.
17 18 19 |
# File 'lib/zwite/core/site.rb', line 17 def apps @apps end |
#apps_path ⇒ Object
Returns the value of attribute apps_path.
11 12 13 |
# File 'lib/zwite/core/site.rb', line 11 def apps_path @apps_path end |
#cache_path ⇒ Object
Returns the value of attribute cache_path.
13 14 15 |
# File 'lib/zwite/core/site.rb', line 13 def cache_path @cache_path end |
#config ⇒ Object
Returns the value of attribute config.
15 16 17 |
# File 'lib/zwite/core/site.rb', line 15 def config @config end |
#config_path ⇒ Object
Returns the value of attribute config_path.
10 11 12 |
# File 'lib/zwite/core/site.rb', line 10 def config_path @config_path end |
#liquid_context ⇒ Object
Returns the value of attribute liquid_context.
19 20 21 |
# File 'lib/zwite/core/site.rb', line 19 def liquid_context @liquid_context end |
#output_path ⇒ Object
Returns the value of attribute output_path.
12 13 14 |
# File 'lib/zwite/core/site.rb', line 12 def output_path @output_path end |
#plugins ⇒ Object
Returns the value of attribute plugins.
16 17 18 |
# File 'lib/zwite/core/site.rb', line 16 def plugins @plugins end |
Instance Method Details
#build ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/zwite/core/site.rb', line 89 def build unless files_changed? return end puts "Building site..." begin self.reset self.preprocess self.generate rescue Exception => e puts "ERROR BUILDING SITE" puts "-------------------" puts e end puts "Building site finished..." end |
#files_changed? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/zwite/core/site.rb', line 21 def files_changed? @timestamps ||= {} = @timestamps.dup # save timestamps @timestamps = {} Dir[self.apps_path + "**/*"].each do |p| path = Pathname.new(p) @timestamps[path.to_s] = path.mtime end # if we have no old_timestamps probably a first generation unless .any? return true end # if we have no timestamps probably a bug unless @timestamps.any? return true end # check if we deleted any files .each do |path, | if @timestamps.fetch(path, nil).nil? return true end end # check if we added any files or modified any @timestamps.each do |path, | = .fetch(path, nil) if .nil? || != return true end end return false end |
#generate ⇒ Object
125 126 127 128 129 130 |
# File 'lib/zwite/core/site.rb', line 125 def generate self.apps.each do |app| app.generate end end |
#load ⇒ Object
Actions
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/zwite/core/site.rb', line 77 def load self.config = YAML.load_file(self.config_path) self.plugins = Zwite::Plugin.subclasses self.apps = [] self.config["apps"].each do |a| self.apps << App.new(self, self.apps_path + a["name"], a["mount"]) end end |
#preprocess ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/zwite/core/site.rb', line 117 def preprocess self.liquid_context = {} self.apps.each do |app| app.preprocess self.liquid_context[app.name] = app end end |
#reset ⇒ Object
110 111 112 113 114 115 |
# File 'lib/zwite/core/site.rb', line 110 def reset if self.output_path.exist? self.output_path.rmtree end self.output_path.mkpath end |