pakyow-presenter/lib/presenter/presenter.rb in pakyow-presenter-0.9.1 vs pakyow-presenter/lib/presenter/presenter.rb in pakyow-presenter-0.10.0

- old
+ new

@@ -22,10 +22,11 @@ end end Pakyow::App.before(:init) { @presenter = Presenter.new + ViewStoreLoader.instance.reset } Pakyow::App.after(:match) { @presenter = Pakyow.app.presenter.dup @presenter.prepare_with_context(context) @@ -102,10 +103,22 @@ def view @composer || @view || raise(MissingView) end + def view?(path) + if composer_for_path(path) + true + else + false + end + end + + def precompose! + self.view = @composer.view + end + def view=(view) @view = view # setting a view means we no longer use/need the composer @composer = nil @@ -166,27 +179,25 @@ @view, @composer = nil self.store = :default end def setup_for_path(path, explicit = false) - @view_stores.each do |name, store| - begin - @composer = store.composer(path) - @path = path - return - rescue MissingView - end + if composer = composer_for_path(path) + @composer = composer + @path = path + return end e = MissingView.new("No view at path '#{path}'") - explicit ? raise(e) : Pakyow.logger.debug(e.message) + explicit ? raise(e) : Pakyow.logger.info(e.message) end def load_views - @view_stores = {} + @view_stores ||= {} - Pakyow::Config.presenter.view_stores.each_pair {|name, path| + Pakyow::Config.presenter.view_stores.each_pair { |name, path| + next unless ViewStoreLoader.instance.modified?(name, path) @view_stores[name] = ViewStore.new(path, name) } end def load_bindings @@ -197,9 +208,20 @@ } end def load_processors @processor_store = Pakyow::App.processors + end + + def composer_for_path(path) + @view_stores.each do |name, store| + begin + return store.composer(path) + rescue MissingView + end + end + + return nil end end end end