class Parcels::Environment
Constants
- PARCELS_WORKAROUND_DIRECTORY_NAME
Attributes
sprockets_environment[R]
widget_trees[R]
Public Class Methods
new(sprockets_environment)
click to toggle source
# File lib/parcels/environment.rb, line 9 def initialize(sprockets_environment) @sprockets_environment = sprockets_environment @widget_trees = [ ] @workaround_directories_for_widget_trees = { } @workaround_directories_root = nil register_engines! end
Public Instance Methods
add_all_widgets_to!(sprockets_context, set_names)
click to toggle source
# File lib/parcels/environment.rb, line 52 def add_all_widgets_to!(sprockets_context, set_names) if widget_trees.length == 0 raise %{Error: You have not defined any widget trees -- directories containing Fortitude widgets. You must call #add_widget_tree! on the Parcels environment, which usually is accessible as #parcels from your Sprockets environment.} end widget_trees.each { |wt| wt.add_all_widgets_to_sprockets_context!(sprockets_context, set_names) } end
add_widget_tree!(widget_tree_root)
click to toggle source
# File lib/parcels/environment.rb, line 23 def add_widget_tree!(widget_tree_root) widget_tree_root = File.expand_path(widget_tree_root, root) widget_tree = widget_trees.detect { |wt| wt.root == widget_tree_root } if (! widget_tree) widget_tree = WidgetTree.new(self, widget_tree_root) widget_trees << widget_tree end widget_tree.add_workaround_directory_to_sprockets!(sprockets_environment) end
create_and_add_all_workaround_directories!()
click to toggle source
# File lib/parcels/environment.rb, line 46 def create_and_add_all_workaround_directories! # widget_trees.each do |widget_tree| # widget_tree.add_workaround_directory_to_sprockets!(sprockets_environment) # end end
is_underneath_root?(filename)
click to toggle source
# File lib/parcels/environment.rb, line 18 def is_underneath_root?(filename) filename = File.expand_path(filename) filename.length > root.length && filename[0..(root.length - 1)] == root end
widget_class_from_file(full_path)
click to toggle source
# File lib/parcels/environment.rb, line 35 def widget_class_from_file(full_path) widget_trees.each do |widget_tree| if (removed = widget_tree.remove_workaround_directory_from(full_path)) full_path = removed break end end ::Fortitude::Widget.widget_class_from_file(full_path, :root_dirs => widget_trees.map(&:widget_naming_root_dirs).flatten.uniq) end
workaround_directories_root()
click to toggle source
# File lib/parcels/environment.rb, line 72 def workaround_directories_root @workaround_directories_root end
workaround_directories_root=(new_root)
click to toggle source
# File lib/parcels/environment.rb, line 76 def workaround_directories_root=(new_root) new_root = File.expand_path(new_root) if @workaround_directories_for_widget_trees.size > 0 && @workaround_directories_root != new_root raise "You can't set the workaround directories root to: #{new_root} ...it's already set to: #{@workaround_directories_root}" end @workaround_directories_root = new_root end
workaround_directory_root_for_widget_tree(widget_tree)
click to toggle source
# File lib/parcels/environment.rb, line 62 def workaround_directory_root_for_widget_tree(widget_tree) @workaround_directories_for_widget_trees[widget_tree] ||= begin if @workaround_directories_root File.join(@workaround_directories_root, workaround_directory_name_for(widget_tree)) else File.join(widget_tree.root, PARCELS_WORKAROUND_DIRECTORY_NAME) end end end
Private Instance Methods
register_engines!()
click to toggle source
# File lib/parcels/environment.rb, line 100 def register_engines! @engines_registered ||= begin if ::Parcels.fortitude_available? @sprockets_environment.register_engine '.rb', ::Parcels::Fortitude::WidgetEngine @sprockets_environment.register_engine '.pcss', ::Parcels::Fortitude::AlongsideEngine end true end end
workaround_directory_name_for(widget_tree)
click to toggle source
# File lib/parcels/environment.rb, line 94 def workaround_directory_name_for(widget_tree) require 'digest/md5' digest = Digest::MD5.hexdigest(widget_tree.root).strip "#{PARCELS_WORKAROUND_DIRECTORY_NAME}_#{digest}" end