Class: Parcels::WidgetTree
- Inherits:
-
Object
- Object
- Parcels::WidgetTree
- Defined in:
- lib/parcels/widget_tree.rb
Instance Attribute Summary collapse
-
#parcels_environment ⇒ Object
readonly
Returns the value of attribute parcels_environment.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #add_all_widgets_to_sprockets_context!(sprockets_context, set_names) ⇒ Object
- #add_workaround_directory_to_sprockets!(sprockets_environment) ⇒ Object
-
#initialize(parcels_environment, root) ⇒ WidgetTree
constructor
A new instance of WidgetTree.
- #remove_workaround_directory_from(full_path) ⇒ Object
- #subpath_to(full_path) ⇒ Object
- #widget_naming_root_dirs ⇒ Object
Constructor Details
#initialize(parcels_environment, root) ⇒ WidgetTree
Returns a new instance of WidgetTree.
15 16 17 18 19 20 |
# File 'lib/parcels/widget_tree.rb', line 15 def initialize(parcels_environment, root) @parcels_environment = parcels_environment @root = File.(root, parcels_environment.root) @sprockets_environments_added_to = { } end |
Instance Attribute Details
#parcels_environment ⇒ Object (readonly)
Returns the value of attribute parcels_environment.
13 14 15 |
# File 'lib/parcels/widget_tree.rb', line 13 def parcels_environment @parcels_environment end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
13 14 15 |
# File 'lib/parcels/widget_tree.rb', line 13 def root @root end |
Instance Method Details
#add_all_widgets_to_sprockets_context!(sprockets_context, set_names) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/parcels/widget_tree.rb', line 59 def (sprockets_context, set_names) return unless root_exists? sprockets_context.depend_on(root) all_parcels = [ ] Find.find(root) do |path| full_path = File.(path, root) stat = File.stat(full_path) sprockets_context.depend_on(path) if stat.directory? next unless stat.file? extension = File.extname(full_path).strip.downcase if (klass = EXTENSION_TO_PARCEL_CLASS_MAP[extension]) parcel = klass.new(self, full_path) if parcel.usable? && parcel.included_in_any_set?(set_names) if all_parcels.length == 0 ensure_workaround_directory_is_set_up! end all_parcels << parcel end end end parcel_list = ::Parcels::DependencyParcelList.new parcel_list.add_parcels!(all_parcels) parcel_list.parcels_in_order.each do |parcel| parcel.add_to_sprockets_context!(sprockets_context) end end |
#add_workaround_directory_to_sprockets!(sprockets_environment) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/parcels/widget_tree.rb', line 26 def add_workaround_directory_to_sprockets!(sprockets_environment) return if (! root_exists?) @sprockets_environments_added_to[sprockets_environment] ||= begin sprockets_environment.prepend_path(workaround_directory) true end end |
#remove_workaround_directory_from(full_path) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/parcels/widget_tree.rb', line 39 def remove_workaround_directory_from(full_path) if (path_under_workaround = ::Parcels::Utils::PathUtils.maybe_path_under(full_path, workaround_directory)) if (separator_index = path_under_workaround.index(File::SEPARATOR)) if (separator_index > 0 && separator_index < (path_under_workaround.length - 1)) link_name = path_under_workaround[0..(separator_index - 1)] after_link = path_under_workaround[(separator_index + 1)..-1] if File.symlink?(File.join(workaround_directory, link_name)) link_value = File.readlink(File.join(workaround_directory, link_name)) resolved_link = File.(File.join(workaround_directory, link_value)) final_path = File.join(resolved_link, after_link) return final_path end end end end nil end |
#subpath_to(full_path) ⇒ Object
35 36 37 |
# File 'lib/parcels/widget_tree.rb', line 35 def subpath_to(full_path) ::Parcels::Utils::PathUtils.path_under(full_path, root) end |
#widget_naming_root_dirs ⇒ Object
22 23 24 |
# File 'lib/parcels/widget_tree.rb', line 22 def ||= [ root, File.dirname(root) ] end |