class ActionViewPreview::Base

Attributes

params[R]

Public Class Methods

all() click to toggle source

Returns all preview classes

# File lib/action_view_preview/base.rb, line 19
def all
  load_previews if descendants.empty?
  descendants
end
call(view_action, params = {}) click to toggle source
# File lib/action_view_preview/base.rb, line 13
def call(view_action, params = {})
  preview = new(params)
  preview.public_send(view_action)
end
exists?(preview) click to toggle source

Returns true if the preview exists

# File lib/action_view_preview/base.rb, line 45
def exists?(preview)
  all.any? { |p| p.preview_name == preview }
end
find(preview) click to toggle source

Find a preview by its underscored class name

# File lib/action_view_preview/base.rb, line 40
 def find(preview)
  all.find { |p| p.preview_name == preview }
end
new(params = {}) click to toggle source
# File lib/action_view_preview/base.rb, line 7
def initialize(params = {})
  @params = params
end
preview_name() click to toggle source

Returns the underscored name of the preview without the suffix

# File lib/action_view_preview/base.rb, line 35
def preview_name
  name.delete_suffix("Preview").underscore
end
view_exists?(view) click to toggle source

Returns true if the view exists.

# File lib/action_view_preview/base.rb, line 30
def view_exists?(view)
  views.include?(view)
end
views() click to toggle source

Returns all of the available views

# File lib/action_view_preview/base.rb, line 25
def views
  public_instance_methods(false).map(&:to_s).sort
end

Private Class Methods

load_previews() click to toggle source
# File lib/action_view_preview/base.rb, line 51
def load_previews
  if preview_path
    Dir["#{preview_path}/**/*_preview.rb"].sort.each { |file| require_dependency file }
  end
end
preview_path() click to toggle source
# File lib/action_view_preview/base.rb, line 57
def preview_path
  ActionViewPreview.preview_path
end