Class: ActionPrompt::Preview
- Inherits:
-
Object
- Object
- ActionPrompt::Preview
- Defined in:
- lib/action_prompt/preview.rb
Class Method Summary collapse
- .all ⇒ Object
- .display_name ⇒ Object
- .find(name) ⇒ Object
- .find_prompt(slug) ⇒ Object
- .load_previews ⇒ Object
- .prompts ⇒ Object
- .slug ⇒ Object
Instance Method Summary collapse
Class Method Details
.all ⇒ Object
11 12 13 14 |
# File 'lib/action_prompt/preview.rb', line 11 def all load_previews if descendants.empty? descendants.sort_by(&:name) end |
.display_name ⇒ Object
24 25 26 |
# File 'lib/action_prompt/preview.rb', line 24 def display_name name.titleize end |
.find(name) ⇒ Object
42 43 44 |
# File 'lib/action_prompt/preview.rb', line 42 def find(name) all.find { |preview| preview.name == name } end |
.find_prompt(slug) ⇒ Object
46 47 48 |
# File 'lib/action_prompt/preview.rb', line 46 def find_prompt(slug) prompts.find { |p| p.slug == slug } end |
.load_previews ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/action_prompt/preview.rb', line 16 def load_previews # TODO: this preview path could be made configurable in order to have equivalent # functionality to Rails mailer previews Dir[Rails.root.join("test", "prompts", "**", "*_preview.rb")].each do |path| require path end end |
.prompts ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/action_prompt/preview.rb', line 32 def prompts # TODO: this might benefit from some memoization prompt_methods = public_instance_methods(false).map(&:to_s).sort prompt_methods.map do |method_name| Prompt.new(name: method_name.humanize, slug: "#{slug}/#{method_name}") end end |
.slug ⇒ Object
28 29 30 |
# File 'lib/action_prompt/preview.rb', line 28 def slug name.delete_suffix("Preview").underscore end |
Instance Method Details
#render(template_name, locals: {}) ⇒ Object
51 52 53 |
# File 'lib/action_prompt/preview.rb', line 51 def render(template_name, locals: {}) ActionPrompt::Renderer.new.render(template_name, locals: locals) end |