Class: Parcels::Environment
- Inherits:
-
Object
- Object
- Parcels::Environment
- Defined in:
- lib/parcels/environment.rb
Instance Attribute Summary collapse
-
#sprockets_environment ⇒ Object
readonly
Returns the value of attribute sprockets_environment.
Instance Method Summary collapse
- #add_all_widgets_to!(sprockets_context, set_names) ⇒ Object
- #add_widget_tree!(widget_tree_root) ⇒ Object
- #create_and_add_all_workaround_directories! ⇒ Object
-
#initialize(sprockets_environment) ⇒ Environment
constructor
A new instance of Environment.
- #is_underneath_root?(filename) ⇒ Boolean
- #widget_class_from_file(full_path) ⇒ Object
- #workaround_directories_root ⇒ Object
- #workaround_directories_root=(new_root) ⇒ Object
- #workaround_directory_root_for_widget_tree(widget_tree) ⇒ Object
Constructor Details
#initialize(sprockets_environment) ⇒ Environment
9 10 11 12 13 14 15 16 |
# File 'lib/parcels/environment.rb', line 9 def initialize(sprockets_environment) @sprockets_environment = sprockets_environment = [ ] = { } @workaround_directories_root = nil register_engines! end |
Instance Attribute Details
#sprockets_environment ⇒ Object (readonly)
Returns the value of attribute sprockets_environment.
5 6 7 |
# File 'lib/parcels/environment.rb', line 5 def sprockets_environment @sprockets_environment end |
Instance Method Details
#add_all_widgets_to!(sprockets_context, set_names) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/parcels/environment.rb', line 52 def (sprockets_context, set_names) if .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 .each { |wt| wt.(sprockets_context, set_names) } end |
#add_widget_tree!(widget_tree_root) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/parcels/environment.rb', line 23 def () = File.(, root) = .detect { |wt| wt.root == } if (! ) = WidgetTree.new(self, ) << end .add_workaround_directory_to_sprockets!(sprockets_environment) end |
#create_and_add_all_workaround_directories! ⇒ Object
46 47 48 49 50 |
# 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) ⇒ Boolean
18 19 20 21 |
# File 'lib/parcels/environment.rb', line 18 def is_underneath_root?(filename) filename = File.(filename) filename.length > root.length && filename[0..(root.length - 1)] == root end |
#widget_class_from_file(full_path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/parcels/environment.rb', line 35 def (full_path) .each do || if (removed = .remove_workaround_directory_from(full_path)) full_path = removed break end end ::Fortitude::Widget.(full_path, :root_dirs => .map(&:widget_naming_root_dirs).flatten.uniq) end |
#workaround_directories_root ⇒ Object
72 73 74 |
# File 'lib/parcels/environment.rb', line 72 def workaround_directories_root @workaround_directories_root end |
#workaround_directories_root=(new_root) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/parcels/environment.rb', line 76 def workaround_directories_root=(new_root) new_root = File.(new_root) if .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) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/parcels/environment.rb', line 62 def () [] ||= begin if @workaround_directories_root File.join(@workaround_directories_root, workaround_directory_name_for()) else File.join(.root, PARCELS_WORKAROUND_DIRECTORY_NAME) end end end |