Class: Lookbook::Engine

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.preview_controllerObject (readonly)

Returns the value of attribute preview_controller.



181
182
183
# File 'lib/lookbook/engine.rb', line 181

def preview_controller
  @preview_controller
end

Class Method Details

.app_nameObject



119
120
121
122
123
124
125
126
# File 'lib/lookbook/engine.rb', line 119

def 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

.component_pathsObject



153
154
155
# File 'lib/lookbook/engine.rb', line 153

def component_paths
  @_component_paths ||= Array(PathUtils.to_absolute(opts.components_path))
end

.hooksObject



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

def hooks
  @_hooks ||= HookStore.init_from_config
end

.inputsObject



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

def inputs
  @_inputs ||= InputStore.init_from_config
end

.last_changedObject



177
178
179
# File 'lib/lookbook/engine.rb', line 177

def last_changed
  @_last_changed ||= (Time.now.to_f * 1000).to_i
end

.mark_changedObject



173
174
175
# File 'lib/lookbook/engine.rb', line 173

def mark_changed
  @_last_changed = nil
end

.mount_pathObject



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

def mount_path
  routes.find_script_name({})
end

.mounted?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/lookbook/engine.rb', line 115

def mounted?
  mount_path.present?
end

.page_pathsObject



157
158
159
# File 'lib/lookbook/engine.rb', line 157

def page_paths
  @_page_paths ||= PathUtils.normalize_paths(opts.page_paths)
end

.pagesObject



165
166
167
# File 'lib/lookbook/engine.rb', line 165

def pages
  @_pages ||= PageCollection.new
end

.panelsObject



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

def panels
  @_panels ||= PanelStore.init_from_config
end

.preview_pathsObject



161
162
163
# File 'lib/lookbook/engine.rb', line 161

def preview_paths
  @_preview_paths ||= PathUtils.normalize_paths(opts.preview_paths)
end

.previewsObject



169
170
171
# File 'lib/lookbook/engine.rb', line 169

def previews
  @_previews ||= PreviewCollection.new
end

.tagsObject



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

def tags
  @_tags ||= TagStore.init_from_config
end

.websocketObject



128
129
130
131
132
133
134
135
# File 'lib/lookbook/engine.rb', line 128

def 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



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

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

#listen?Boolean

Returns:

  • (Boolean)


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

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

#optsObject



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

def opts
  Lookbook.config
end

#parserObject



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

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

#processObject



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

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

#run_hooks(event_name, *args) ⇒ Object



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

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