lib/hippo/extension.rb in hippo-fw-0.9.1 vs lib/hippo/extension.rb in hippo-fw-0.9.2
- old
+ new
@@ -15,15 +15,15 @@
require screens_config
end
end
end
- # lock the current controlling extension so that it can't
- # be changed by other extensions that are loaded later
- def lock_controlling!
- self.controlling_locked=true
- end
+ # # lock the current controlling extension so that it can't
+ # # be changed by other extensions that are loaded later
+ # def lock_controlling!
+ # self.controlling_locked=true
+ # end
def add(klass)
@cached_instances = nil
if Extensions.controlling_locked
ALL.unshift(klass)
@@ -76,20 +76,49 @@
last = ALL.last
each{|ext| return ext if ext.is_a?(last) }
Hippo.logger.error "Unable to find controlling extension. #{sorted} are loaded"
end
+ # Loads the code for the extension that the user is currently
+ # working inside. The `hippo` command uses this to detect
+ # what actions should be taken.
+ #
+ # Will silently swallow any exceptions that are raised when the file is required and return nil
+ #
+ # @return [Extension] extension that was loaded, nil if none was found
+ def bootstrap(raise_on_fail:false)
+ ext = Dir.glob("./lib/*/extension.rb").first
+ if ext
+ begin
+ require(ext)
+ rescue =>e
+ stack = e.backtrace[0..4].join("\n")
+ raise Thor::Error.new("Loading ./lib/*/extension.rb failed with: #{e}\n#{stack}")
+ end
+ Extensions.controlling
+ else
+ return _maybe_fail(raise_on_fail)
+ end
+ end
+
+ def _maybe_fail(should_raise)
+ raise Thor::Error.new("Unable to locate Hippo environment.\nDoes ./lib/*/extension.rb exist?") if should_raise
+ return nil
+ end
+
+
def client_bootstrap_data
- data = {
- api_path: Hippo.config.api_path,
- root_path: Hippo.config.mounted_at,
- root_view: Hippo.config.root_view,
- environment: Hippo.config.environment,
- assets_path_prefix: Hippo.config.assets_path_prefix,
- controlling_extension: controlling.identifier,
- initial_workspace_screen_id: Hippo.config.initial_workspace_screen_id
- }
+ data = {}
+ %w{
+ api_path environment website_domain product_name assets_path_prefix
+ }.each do |config|
+ data[config.to_sym] = Hippo.config.send(config)
+ end
+ data.merge(
+ controlling_extension: controlling.identifier,
+ initial_workspace_screen_id: Hippo.config.initial_workspace_screen_id
+ )
each do | ext |
ext_data = ext.client_bootstrap_data
data[ext.identifier] = ext_data unless ext_data.nil?
end
return data
@@ -98,9 +127,15 @@
def load_controlling_config
config_file = self.controlling.root_path.join('config','initialize.rb')
if config_file.exist?
require config_file
end
+ end
+
+ def client_module_paths
+ map { |e| e.root_path.join('client').to_s }.reverse + [
+ controlling.root_path.join('node_modules').to_s
+ ]
end
end
end