Skip to content

Commit

Permalink
Whole bunch of rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Dec 27, 2023
1 parent 914e51b commit 5194dfd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/views/components/application_view_component.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationViewComponent < ViewComponentContrib::Base
extend Dry::Initializer
end
2 changes: 2 additions & 0 deletions app/views/components/application_view_component_preview.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationViewComponentPreview < ViewComponentContrib::Preview::Base
self.abstract_class = true
end
4 changes: 2 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

module MushroomObserver
class Application < Rails::Application
config.autoload_paths << Rails.root.join("app", "views", "components")
config.view_component.preview_paths << Rails.root.join("app", "views", "components")
config.autoload_paths << Rails.root.join("app/views/components")
config.view_component.preview_paths << Rails.root.join("app/views/components")
# Settings in config/environments/* take precedence over those
# specified here.
# Application configuration should go into files in config/initializers
Expand Down
6 changes: 4 additions & 2 deletions config/initializers/view_component.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

ActiveSupport.on_load(:view_component) do
# Extend your preview controller to support authentication and other
# application-specific stuff
Expand All @@ -10,7 +12,7 @@
#
# Make it possible to store previews in sidecar folders
# See https://github.com/palkan/view_component-contrib#organizing-components-or-sidecar-pattern-extended
ViewComponent::Preview.extend ViewComponentContrib::Preview::Sidecarable
ViewComponent::Preview.extend(ViewComponentContrib::Preview::Sidecarable)
# Enable `self.abstract_class = true` to exclude previews from the list
ViewComponent::Preview.extend ViewComponentContrib::Preview::Abstract
ViewComponent::Preview.extend(ViewComponentContrib::Preview::Abstract)
end
21 changes: 15 additions & 6 deletions lib/generators/view_component/view_component_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,39 @@ class ViewComponentGenerator < Rails::Generators::NamedBase
argument :attributes, type: :array, default: [], banner: "attribute"

def create_component_file
template "component.rb", File.join("app/views/components", class_path, file_name, "component.rb")
template("component.rb",
File.join("app/views/components", class_path, file_name,
"component.rb"))
end

def create_template_file
template "component.html.erb", File.join("app/views/components", class_path, file_name, "component.html.erb")
template("component.html.erb",
File.join("app/views/components", class_path, file_name,
"component.html.erb"))
end

def create_test_file
return if options[:skip_test]

template "component_test.rb", File.join("test/views/components", class_path, "#{file_name}_test.rb")
template("component_test.rb",
File.join("test/views/components", class_path,
"#{file_name}_test.rb"))
end

def create_system_test_file
return if options[:skip_system_test]

template "component_system_test.rb", File.join("test/system/views/components", class_path, "#{file_name}_test.rb")
template("component_system_test.rb",
File.join("test/system/views/components", class_path,
"#{file_name}_test.rb"))
end

def create_preview_file
return if options[:skip_preview]

template "preview.rb", File.join("app/views/components", class_path, file_name, "preview.rb")
template("preview.rb",
File.join("app/views/components", class_path, file_name,
"preview.rb"))
end

private
Expand All @@ -51,5 +61,4 @@ def initialize_signature

attributes.map { |attr| "option :#{attr.name}" }.join("\n ")
end

end

0 comments on commit 5194dfd

Please sign in to comment.