Module: ReactManifest
- Defined in:
- lib/react_manifest.rb,
lib/react_manifest/railtie.rb,
lib/react_manifest/scanner.rb,
lib/react_manifest/version.rb,
lib/react_manifest/watcher.rb,
lib/react_manifest/reporter.rb,
lib/react_manifest/generator.rb,
lib/react_manifest/view_helpers.rb,
lib/react_manifest/configuration.rb,
lib/react_manifest/dependency_map.rb,
lib/react_manifest/layout_patcher.rb,
lib/react_manifest/tree_classifier.rb,
lib/react_manifest/application_analyzer.rb,
lib/react_manifest/application_migrator.rb,
lib/react_manifest/sprockets_manifest_patcher.rb
Overview
rubocop:disable Metrics/ModuleLength
Defined Under Namespace
Modules: ViewHelpers, Watcher Classes: ApplicationAnalyzer, ApplicationMigrator, Configuration, DependencyMap, Generator, LayoutPatcher, Railtie, Reporter, Scanner, SprocketsManifestPatcher, TreeClassifier
Constant Summary collapse
- VERSION =
"0.2.22".freeze
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .reset! ⇒ Object
-
.resolve_bundle_for_component(component_name) ⇒ Object
Resolve a controller bundle from a React component symbol.
-
.resolve_bundles(ctrl_name) ⇒ Object
Returns the ordered list of bundle logical names for a given controller.
-
.resolve_bundles_for_component(component_name) ⇒ Object
Resolve all controller bundles needed for a React component symbol.
-
.resolve_bundles_for_component_direct(component_name) ⇒ Object
Resolve the direct bundle list needed for a React component symbol.
Class Method Details
.configuration ⇒ Object
21 22 23 |
# File 'lib/react_manifest.rb', line 21 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
25 26 27 |
# File 'lib/react_manifest.rb', line 25 def configure yield configuration end |
.reset! ⇒ Object
29 30 31 |
# File 'lib/react_manifest.rb', line 29 def reset! @configuration = nil end |
.resolve_bundle_for_component(component_name) ⇒ Object
Resolve a controller bundle from a React component symbol.
This is primarily used to support react-rails ‘react_component` calls, where the requested component name is known and may not align 1:1 with controller_path-derived bundle names.
68 69 70 |
# File 'lib/react_manifest.rb', line 68 def resolve_bundle_for_component(component_name) resolve_bundles_for_component_direct(component_name).last end |
.resolve_bundles(ctrl_name) ⇒ Object
Returns the ordered list of bundle logical names for a given controller. Used by the react_bundle_tag view helper.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/react_manifest.rb', line 35 def resolve_bundles(ctrl_name) config = configuration bundles = [] # 1. Shared bundle always first shared = resolve_bundle_reference(config, config.shared_bundle) bundles << shared if shared # 2. always_include bundles (e.g. ux_main) config.always_include.each do |b| resolved = resolve_bundle_reference(config, b) bundles << resolved if resolved && !bundles.include?(resolved) end # 3. Controller-specific bundle # Try fully-namespaced first: admin/users → ux_admin_users # Then drop segments: ux_admin controller_candidates(ctrl_name).each do |candidate| resolved = resolve_bundle_reference(config, candidate) if resolved && !bundles.include?(resolved) bundles << resolved break end end bundles end |
.resolve_bundles_for_component(component_name) ⇒ Object
Resolve all controller bundles needed for a React component symbol. Includes transitive controller-bundle dependencies inferred from component symbol usage across ux/app/* directories.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/react_manifest.rb', line 100 def resolve_bundles_for_component(component_name) name = component_name.to_s return [] if name.empty? config = configuration maps = component_maps(config) root_bundle = maps[:symbol_to_bundle][name] return [] unless root_bundle ordered = [] visiting = Set.new visited = Set.new walk = lambda do |bundle_name| return if visited.include?(bundle_name) || visiting.include?(bundle_name) visiting << bundle_name maps[:bundle_dependencies].fetch(bundle_name, Set.new).each { |dep| walk.call(dep) } visiting.delete(bundle_name) visited << bundle_name ordered << bundle_name end walk.call(root_bundle) ordered.filter_map { |bundle_name| resolve_bundle_reference(config, bundle_name) } end |
.resolve_bundles_for_component_direct(component_name) ⇒ Object
Resolve the direct bundle list needed for a React component symbol. Returns shared first (if present), then the component’s owning bundle.
Unlike resolve_bundles_for_component, this does not include transitive controller dependencies because generated controller manifests already inline those files via Sprockets require directives.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/react_manifest.rb', line 78 def resolve_bundles_for_component_direct(component_name) name = component_name.to_s return [] if name.empty? config = configuration maps = component_maps(config) root_bundle = maps[:symbol_to_bundle][name] return [] unless root_bundle bundles = [] shared = resolve_bundle_reference(config, config.shared_bundle) bundles << shared if shared root = resolve_bundle_reference(config, root_bundle) bundles << root if root && !bundles.include?(root) bundles end |