Skip to content

Add controller generator and test #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
tailwindcss-rails-webpacker (0.2.0)
tailwindcss-rails-webpacker (0.2.1)
rails (>= 6.0.0)

GEM
Expand Down Expand Up @@ -143,4 +143,4 @@ DEPENDENCIES
tailwindcss-rails-webpacker!

BUNDLED WITH
2.1.4
2.2.28
16 changes: 16 additions & 0 deletions lib/generators/tailwindcss/controller/controller_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails/generators/erb/controller/controller_generator'

module Tailwindcss
module Generators
class ControllerGenerator < Erb::Generators::ControllerGenerator
source_root File.expand_path("../templates", __FILE__)

protected

def handler
:erb
end

end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="text-lg font-bold text-4xl">
<%= class_name %>#<%= @action %>
</h1>
<p class="my-5">
Find me in <%= @path %>
</p>
</div>
2 changes: 1 addition & 1 deletion lib/tailwindcss/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Tailwindcss
VERSION = "0.2.0"
VERSION = "0.2.1"
end
32 changes: 32 additions & 0 deletions test/lib/generators/tailwindcss/controller_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "./test/test_helper"
require "generators/tailwindcss/controller/controller_generator"

class Tailwindcss::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
GENERATION_PATH = File.expand_path("../tmp", File.dirname(__FILE__))

tests Tailwindcss::Generators::ControllerGenerator
destination GENERATION_PATH

setup :prepare_destination

arguments %w[Account foo bar]

Minitest.after_run do
FileUtils.rm_rf GENERATION_PATH
end

test "should invoke template engine" do
run_generator
assert_file "app/views/account/foo.html.erb"
assert_file "app/views/account/bar.html.erb"
end

test "should revoke template engine" do
run_generator
run_generator ["account"], behavior: :revoke

assert_no_file "app/views/account"
assert_no_file "app/views/account/foo.html.erb"
assert_no_file "app/views/account/bar.html.erb"
end
end
4 changes: 2 additions & 2 deletions test/lib/generators/tailwindcss/scaffold_generator_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require "./test/test_helper"
require "generators/tailwindcss/scaffold/scaffold_generator"

class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
Expand All @@ -18,4 +18,4 @@ class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCa

%w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" }
end
end
end
2 changes: 1 addition & 1 deletion test/tailwindcss/rails/webpacker_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require "./test/test_helper"

class TailwindcssTest < ActiveSupport::TestCase
test "it has a version number" do
Expand Down