Skip to content

Commit

Permalink
Move dev dependencies to Gemfile and fix versions (#15)
Browse files Browse the repository at this point in the history
* Move dev dependencies to Gemfile and fix versions

* Fix lint issue
  • Loading branch information
JulianPasquale authored Nov 29, 2023
1 parent 43dc98d commit 900aa0d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 132 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ node_modules/
package.json
spec/tmp/
yarn.lock
bun.lockb
108 changes: 21 additions & 87 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,100 +1,34 @@
AllCops:
TargetRubyVersion: 2.5

Style/Documentation:
Enabled: false
inherit_mode:
merge:
- Exclude

Layout/SpaceBeforeFirstArg:
Exclude:

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*
require:
- rubocop-rspec
- rubocop-rake

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Metrics/AbcSize:
# The ABC size is a calculated magnitude, so this number can be an Integer or
# a Float.
Max: 15
AllCops:
NewCops: enable
TargetRubyVersion: 2.7

Metrics/BlockLength:
CountComments: false
Max: 25
Naming/FileName:
Exclude:
- '*.gemspec'
- config/**/*
- spec/**/*
ExcludedMethods:
- class_methods

Metrics/BlockNesting:
Max: 4

Metrics/ClassLength:
CountComments: false
Max: 200

# Avoid complex methods.
Metrics/CyclomaticComplexity:
Max: 7
- 'lib/htmx-rails.rb'

Metrics/MethodLength:
CountComments: false
Max: 24

Metrics/ModuleLength:
CountComments: false
Max: 200

Layout/LineLength:
Max: 100
# To make it possible to copy or click on URIs in the code, we allow lines
# containing a URI to be longer than Max.
AllowURI: true
URISchemes:
- http
- https

Metrics/ParameterLists:
Max: 5
CountKeywordArgs: true

Metrics/PerceivedComplexity:
Max: 12

Style/ExponentialNotation:
Enabled: true
Gemspec/RequireMFA:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: true
RSpec/BeforeAfterAll:
Enabled: false

Style/ModuleFunction:
Style/Documentation:
Enabled: false

Style/RescueModifier:
Exclude:
- spec/**/*
RSpec/FilePath:
Enabled: false

Naming/PredicateName:
RSpec/SpecFilePathFormat:
Enabled: false

Naming/FileName:
RSpec/AnyInstance:
Exclude:
- lib/htmx-rails.rb

Style/HashEachMethods:
Enabled: true

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true
- 'spec/lib/generators/install_generator_spec.rb'
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in htmx-rails.gemspec
gemspec

gem 'generator_spec', '~> 0.9.4'
gem 'psych', '>= 5.1.1.1' # pinned due to https://github.com/ruby/psych/issues/655
gem 'rake', '~> 13.1'
gem 'reek', '~> 6.1'
gem 'rspec', '~> 3.12'
gem 'rubocop', '~> 1.57'
gem 'rubocop-rake', '~> 0.6'
gem 'rubocop-rspec', '~> 2.25'
gem 'simplecov', '~> 0.17.1'
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :spec

desc 'Run analysis tools to ensure code quality'
task :code_analysis do
sh 'bundle exec rubocop lib spec'
sh 'bundle exec reek lib'
Expand Down
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'htmx/rails'
Expand Down
40 changes: 17 additions & 23 deletions htmx-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@
require_relative 'lib/htmx/rails/version'

Gem::Specification.new do |spec|
spec.name = 'htmx-rails'
spec.version = Htmx::Rails::VERSION
spec.authors = ['Julian Pasquale']
spec.email = ['[email protected]']
spec.summary = 'Ruby gem for use HTMX in Rails applications'
spec.description = 'Ruby gem for use HTMX in Rails applications'
spec.homepage = 'https://github.com/rootstrap/htmx-rails'
spec.license = 'MIT'
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
spec.name = 'htmx-rails'
spec.version = Htmx::Rails::VERSION
spec.authors = ['Julian Pasquale']
spec.email = ['[email protected]']
spec.summary = 'Ruby gem for use HTMX in Rails applications'
spec.description = 'Ruby gem for use HTMX in Rails applications'
spec.homepage = 'https://github.com/rootstrap/htmx-rails'
spec.license = 'MIT'

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = 'https://github.com/rootstrap/htmx-rails'
spec.metadata["changelog_uri"] = 'https://github.com/rootstrap/htmx-rails'
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')

spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*']
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/rootstrap/htmx-rails'
spec.metadata['changelog_uri'] = 'https://github.com/rootstrap/htmx-rails'

spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*']
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

# Development dependencies.
spec.add_development_dependency 'generator_spec'
spec.add_development_dependency 'psych', '>= 5.1.1.1' # pinned due to https://github.com/ruby/psych/issues/655
spec.add_development_dependency 'rake'
spec.add_development_dependency 'reek'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_dependency 'rails', '>= 5.0'
end
21 changes: 8 additions & 13 deletions lib/generators/htmx/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ class InstallGenerator < ::Rails::Generators::Base

# Setup HTMX
def setup
if bun?
setup_bun
elsif importmap?
setup_importmap
elsif webpacker?
setup_webpacker
elsif sprockets?
setup_sprockets
else
raise 'No known asset pipeline detected'
end
return setup_bun if bun?
return setup_importmap if importmap?
return setup_webpacker if webpacker?
return setup_sprockets if sprockets?

raise 'No known asset pipeline detected.'
end

private
Expand Down Expand Up @@ -62,7 +57,7 @@ def setup_bun
end

def setup_importmap
run "bin/importmap pin htmx.org#{Htmx::Rails::HTMX_VERSION}"
run "bin/importmap pin htmx.org@#{Htmx::Rails::HTMX_VERSION}"

add_to_manifest(manifest('app/javascript'), IMPORTMAP_SETUP)
end
Expand All @@ -72,7 +67,7 @@ def setup_sprockets
end

def setup_webpacker
run "yarn add htmx.org#{Htmx::Rails::HTMX_VERSION}"
run "yarn add htmx.org@#{Htmx::Rails::HTMX_VERSION}"

add_to_manifest(manifest(webpack_source_path), WEBPACKER_SETUP)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

RSpec.describe Htmx::Generators::InstallGenerator, type: :generator do
RSpec.describe Htmx::Generators::InstallGenerator do
include Support::FilesHelper

destination File.expand_path('../tmp', __dir__)
Expand All @@ -29,7 +29,7 @@
run_generator
assert_file(
'app/assets/javascripts/application.js',
"\n#{Htmx::Generators::InstallGenerator::SPROCKETS_SETUP}"
"\n#{described_class::SPROCKETS_SETUP}"
)
end
end
Expand All @@ -39,7 +39,7 @@
run_generator
assert_file(
'app/assets/javascripts/application.js',
Htmx::Generators::InstallGenerator::SPROCKETS_SETUP
described_class::SPROCKETS_SETUP
)
end
end
Expand All @@ -51,9 +51,8 @@
hide_const('Sprockets')
hide_const('Importmap')

expect_any_instance_of(Htmx::Generators::InstallGenerator)
allow_any_instance_of(described_class)
.to receive(:webpack_source_path)
.at_least(1).time
.and_return(File.join("#{destination_root}/app/javascript/packs"))
end

Expand All @@ -66,7 +65,7 @@
run_generator
assert_file(
'app/javascript/packs/application.js',
Htmx::Generators::InstallGenerator::WEBPACKER_SETUP
described_class::WEBPACKER_SETUP
)
end
end
Expand All @@ -76,7 +75,7 @@
run_generator
assert_file(
'app/javascript/packs/application.js',
Htmx::Generators::InstallGenerator::WEBPACKER_SETUP
described_class::WEBPACKER_SETUP
)
end
end
Expand Down Expand Up @@ -152,7 +151,7 @@
end

it 'raise an error' do
expect { run_generator }.to raise_error('No known asset pipeline detected')
expect { run_generator }.to raise_error('No known asset pipeline detected.')
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require 'htmx-rails'

# Support files
require 'support/files_helper'
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down

0 comments on commit 900aa0d

Please sign in to comment.