Class: Lookbook::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/lookbook/engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_nameObject



114
115
116
117
118
119
120
121
# File 'lib/lookbook/engine.rb', line 114

def self.app_name
  name = if Rails.application.class.respond_to?(:module_parent_name)
    Rails.application.class.module_parent_name
  else
    Rails.application.class.parent_name
  end
  name.underscore
end

.hooksObject



144
145
146
# File 'lib/lookbook/engine.rb', line 144

def self.hooks
  @hooks ||= HookStore.init_from_config
end

.inputsObject



136
137
138
# File 'lib/lookbook/engine.rb', line 136

def self.inputs
  @inputs ||= InputStore.init_from_config
end

.mount_pathObject



106
107
108
# File 'lib/lookbook/engine.rb', line 106

def self.mount_path
  routes.find_script_name({})
end

.mounted?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/lookbook/engine.rb', line 110

def self.mounted?
  mount_path.present?
end

.panelsObject



132
133
134
# File 'lib/lookbook/engine.rb', line 132

def self.panels
  @panels ||= PanelStore.init_from_config
end

.preview_controllerObject



148
149
150
# File 'lib/lookbook/engine.rb', line 148

def self.preview_controller
  @preview_controller
end

.tagsObject



140
141
142
# File 'lib/lookbook/engine.rb', line 140

def self.tags
  @tags ||= TagStore.init_from_config
end

.websocketObject



123
124
125
126
127
128
129
130
# File 'lib/lookbook/engine.rb', line 123

def self.websocket
  if mounted?
    use_websocket = opts.auto_refresh && opts.listen && process.supports_listening?
    @websocket ||= use_websocket ? Websocket.new(mount_path, logger: Lookbook.logger) : Websocket.noop
  else
    Websocket.noop
  end
end

Instance Method Details

#file_watcherObject



94
95
96
# File 'lib/lookbook/engine.rb', line 94

def file_watcher
  @file_watcher ||= FileWatcher.new(force_polling: opts.listen_use_polling)
end

#listen?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/lookbook/engine.rb', line 102

def listen?
  opts.listen && process.supports_listening?
end

#optsObject



80
81
82
# File 'lib/lookbook/engine.rb', line 80

def opts
  Lookbook.config
end

#parserObject



90
91
92
# File 'lib/lookbook/engine.rb', line 90

def parser
  @parser ||= PreviewParser.new(opts.preview_paths, Engine.tags)
end

#processObject



98
99
100
# File 'lib/lookbook/engine.rb', line 98

def process
  @process ||= Process.new(env: Rails.env)
end

#run_hooks(event_name, *args) ⇒ Object



84
85
86
87
88
# File 'lib/lookbook/engine.rb', line 84

def run_hooks(event_name, *args)
  self.class.hooks.for_event(event_name).each do |hook|
    hook.call(Lookbook, *args)
  end
end