action_view_preview 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 143b01a8f2f804443f8b5a6894acab8f0a077bd6465a2bfb2a0e13440af553b9
4
- data.tar.gz: 902199c1a8f455d4cdb10655f3e812f315d4861f60b9c14a8efd8d697b5382d9
3
+ metadata.gz: 0df4dc41ff998ad490e65caace4beb0c6440d30b5057d4bf8d8c5abaca650cc5
4
+ data.tar.gz: dbdfaba6e935fe35602c79fe458905af2be6ca95b68d37a8c26cf3179a8bb92f
5
5
  SHA512:
6
- metadata.gz: d527e086a7835cd02fe3d1fb0f97f96b340f3f392be4271cd6ddddd83854729a43f605f7f8a1999f79f99a118f0095e3e43391abf9208547f7298913d4b428ee
7
- data.tar.gz: a105ad9734d535800ea73e028ff1eb23b44708cff75e5624b06c442bd5430b3d4d0e0f19dc60997f48663211e77421a79dbe7a419c6d8d1821f38a250074d31c
6
+ metadata.gz: 9add839c2bfa7fb1e7963a13310ee25a8eb5153281561459f820b388f1542ae44484070699ed08118f5844698d62a4b047892cb0db877f7b87407f4bffaecf44
7
+ data.tar.gz: d515accf986e5c108575212f08a3019a264a6a16697d9ffb5f51dd20b8bceb7c2e0d936e7ba8ae9f9f56ba493840039fa09b9251f9475dce33a423ad3cb47aa9
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ActionViewPreview
2
2
  Sometimes being able to preview a view might come in handy, like when a view is going to be used only inside a PDF, for example.
3
3
 
4
- This gem allows a setup similar `ActionMailer::Base`, and provides a development tool for rendering and debugging views that wouldn't otherwise be rendered in your application.
4
+ This gem allows a setup similar `ActionMailer::Preview`, and provides a development tool for rendering and debugging views that wouldn't otherwise be rendered in your application.
5
5
 
6
6
  ## Installation
7
7
  Add this line to your application's Gemfile:
@@ -21,6 +21,11 @@ $ gem install action_view_preview
21
21
  ```
22
22
 
23
23
  ## Usage
24
+ ### Command Line Install
25
+
26
+ Run `rails generate action_view_preview:install` and the generator should create a `hello_preview.rb` and mount the route in your `routes.rb` file, similar to the steps shown below in the manual install.
27
+
28
+ ### Manual Install
24
29
  1. Mount the engine in your `routes.rb`:
25
30
 
26
31
  ```ruby
@@ -1,5 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+
1
5
  module ActionViewPreview
2
6
  class Engine < ::Rails::Engine
3
7
  isolate_namespace ActionViewPreview
8
+
9
+ config.action_view_preview = ActionViewPreview
10
+ config.eager_load_namespaces << ActionViewPreview
11
+
12
+ initializer "action_view_preview.set_configs" do |app|
13
+ options = app.config.action_view_preview
14
+
15
+ options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/views/previews" : nil
16
+
17
+ ActiveSupport.on_load(:action_view_preview) do
18
+ options.each { |k, v| ActionViewPreview.send("#{k}=", v) }
19
+ end
20
+ end
21
+
22
+ initializer "action_view_preview.set_autoload_paths" do |app|
23
+ options = app.config.action_view_preview
24
+
25
+ if options.preview_path
26
+ ActiveSupport::Dependencies.autoload_paths << options.preview_path
27
+ end
28
+ end
4
29
  end
5
30
  end
31
+
32
+ require 'action_view_preview' if !defined?(ActionViewPreview::Base)
@@ -1,3 +1,3 @@
1
1
  module ActionViewPreview
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -1,19 +1,16 @@
1
1
  require "action_view_preview/version"
2
- require "action_view_preview/engine"
2
+ require "active_support/dependencies/autoload"
3
3
 
4
4
  module ActionViewPreview
5
5
  extend ::ActiveSupport::Autoload
6
6
 
7
7
  autoload :Base
8
8
 
9
- mattr_accessor :preview_path
9
+ mattr_accessor :preview_path, instance_writer: false
10
10
 
11
11
  def self.setup
12
12
  yield self
13
13
  end
14
-
15
- def self.preview_path
16
- @@preview_path || "#{Rails.root}/test/views/previews"
17
- end
18
-
19
14
  end
15
+
16
+ require "action_view_preview/engine" if defined?(Rails::Engine)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ class ActionViewPreviewGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ argument :name, type: :string, required: true, banner: 'NAME'
9
+ argument :actions, type: :array, default: [], banner: 'action action'
10
+
11
+ def execute
12
+ actions.map!(&:underscore)
13
+
14
+ template 'test/views/previews/%file_name%_preview.rb', "#{ActionViewPreview.preview_path}/%file_name%_preview.rb"
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "rails/generators"
2
+
3
+ module ActionViewPreview
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc 'Mounts the action view preview module in routes'
6
+
7
+ def mount_engine
8
+ route 'mount ActionViewPreview::Engine => "/action_view_preview"'
9
+ end
10
+
11
+ def execute
12
+ generate 'action_view_preview Hello hello_world'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name %>ViewPreview < ActionViewPreview::Base
2
+ <% actions.each do |action| -%>
3
+ def <%= action %>
4
+ end
5
+ <%= "\n" unless action == actions.last -%>
6
+ <% end -%>
7
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_view_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Campanari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-29 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.1'
27
27
  description: A development tool for rendering and debugging views that wouldn't otherwise
@@ -54,7 +54,9 @@ files:
54
54
  - lib/action_view_preview/base.rb
55
55
  - lib/action_view_preview/engine.rb
56
56
  - lib/action_view_preview/version.rb
57
- - lib/tasks/action_view_preview_tasks.rake
57
+ - lib/generators/action_view_preview/action_view_preview_generator.rb
58
+ - lib/generators/action_view_preview/install_generator.rb
59
+ - lib/generators/action_view_preview/templates/test/views/previews/%file_name%_preview.rb.tt
58
60
  homepage: https://github.com/lcampanari/action_view_preview
59
61
  licenses:
60
62
  - MIT
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
79
  - !ruby/object:Gem::Version
78
80
  version: '0'
79
81
  requirements: []
80
- rubygems_version: 3.0.9
82
+ rubygems_version: 3.1.6
81
83
  signing_key:
82
84
  specification_version: 4
83
85
  summary: Views preview for Rails
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :action_view_preview do
3
- # # Task goes here
4
- # end