Skip to content

Commit

Permalink
Coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Sep 30, 2024
1 parent 7838556 commit 4450ee6
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AllCops:
- bin/*
- gemfiles/*
- spec/dummy/**/*
- lib/generators/**/*.rb
- lib/generators/smart_listing/templates/*.rb

Gemspec/RequireMFA:
Enabled: false
Expand Down
16 changes: 10 additions & 6 deletions lib/generators/smart_listing/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# frozen_string_literal: true

require 'rails/generators'

module SmartListing
module Generators
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path('templates', __dir__)

def self.banner #:nodoc:
<<-BANNER.chomp
rails g smart_listing:install
def self.banner # :nodoc:
<<~BANNER.chomp
rails g smart_listing:install
Copies initializer file
BANNER
Copies initializer file
BANNER
end

desc ''
Expand Down
146 changes: 74 additions & 72 deletions lib/generators/smart_listing/templates/initializer.rb
Original file line number Diff line number Diff line change
@@ -1,91 +1,93 @@
# frozen_string_literal: true

SmartListing.configure do |config|
config.global_options({
#:param_names => { # param names
#:page => :page,
#:per_page => :per_page,
#:sort => :sort,
#},
#:array => false, # controls whether smart list should be using arrays or AR collections
#:max_count => nil, # limit number of rows
#:unlimited_per_page => false, # allow infinite page size
#:paginate => true, # allow pagination
#:memorize_per_page => false, # save per page settings in the cookie
#:page_sizes => DEFAULT_PAGE_SIZES, # set available page sizes array
#:kaminari_options => {:theme => "smart_listing"}, # Kaminari's paginate helper options
#:sort_dirs => [nil, "asc", "desc"], # Default sorting directions cycle of sortables
# :param_names => { # param names
# :page => :page,
# :per_page => :per_page,
# :sort => :sort,
# },
# :array => false, # controls whether smart list should be using arrays or AR collections
# :max_count => nil, # limit number of rows
# :unlimited_per_page => false, # allow infinite page size
# :paginate => true, # allow pagination
# :memorize_per_page => false, # save per page settings in the cookie
# :page_sizes => DEFAULT_PAGE_SIZES, # set available page sizes array
# :kaminari_options => {:theme => "smart_listing"}, # Kaminari's paginate helper options
# :sort_dirs => [nil, "asc", "desc"], # Default sorting directions cycle of sortables
})

config.constants :classes, {
#:main => "smart-listing",
#:editable => "editable",
#:content => "content",
#:loading => "loading",
#:status => "smart-listing-status",
#:item_actions => "actions",
#:new_item_placeholder => "new-item-placeholder",
#:new_item_action => "new-item-action",
#:new_item_button => "btn",
#:hidden => "hidden",
#:autoselect => "autoselect",
#:callback => "callback",
#:pagination_wrapper => "text-center",
#:pagination_container => "pagination",
#:pagination_per_page => "pagination-per-page text-center",
#:inline_editing => "info",
#:no_records => "no-records",
#:limit => "smart-listing-limit",
#:limit_alert => "smart-listing-limit-alert",
#:controls => "smart-listing-controls",
#:controls_reset => "reset",
#:filtering => "filter",
#:filtering_search => "glyphicon-search",
#:filtering_cancel => "glyphicon-remove",
#:filtering_disabled => "disabled",
#:sortable => "sortable",
#:icon_new => "glyphicon glyphicon-plus",
#:icon_edit => "glyphicon glyphicon-pencil",
#:icon_trash => "glyphicon glyphicon-trash",
#:icon_inactive => "glyphicon glyphicon-circle",
#:icon_show => "glyphicon glyphicon-share-alt",
#:icon_sort_none => "glyphicon glyphicon-resize-vertical",
#:icon_sort_up => "glyphicon glyphicon-chevron-up",
#:icon_sort_down => "glyphicon glyphicon-chevron-down",
#:muted => "text-muted",
# :main => "smart-listing",
# :editable => "editable",
# :content => "content",
# :loading => "loading",
# :status => "smart-listing-status",
# :item_actions => "actions",
# :new_item_placeholder => "new-item-placeholder",
# :new_item_action => "new-item-action",
# :new_item_button => "btn",
# :hidden => "hidden",
# :autoselect => "autoselect",
# :callback => "callback",
# :pagination_wrapper => "text-center",
# :pagination_container => "pagination",
# :pagination_per_page => "pagination-per-page text-center",
# :inline_editing => "info",
# :no_records => "no-records",
# :limit => "smart-listing-limit",
# :limit_alert => "smart-listing-limit-alert",
# :controls => "smart-listing-controls",
# :controls_reset => "reset",
# :filtering => "filter",
# :filtering_search => "glyphicon-search",
# :filtering_cancel => "glyphicon-remove",
# :filtering_disabled => "disabled",
# :sortable => "sortable",
# :icon_new => "glyphicon glyphicon-plus",
# :icon_edit => "glyphicon glyphicon-pencil",
# :icon_trash => "glyphicon glyphicon-trash",
# :icon_inactive => "glyphicon glyphicon-circle",
# :icon_show => "glyphicon glyphicon-share-alt",
# :icon_sort_none => "glyphicon glyphicon-resize-vertical",
# :icon_sort_up => "glyphicon glyphicon-chevron-up",
# :icon_sort_down => "glyphicon glyphicon-chevron-down",
# :muted => "text-muted",
}

config.constants :data_attributes, {
#:main => "smart-listing",
#:controls_initialized => "smart-listing-controls-initialized",
#:confirmation => "confirmation",
#:id => "id",
#:href => "href",
#:callback_href => "callback-href",
#:max_count => "max-count",
#:item_count => "item-count",
#:inline_edit_backup => "smart-listing-edit-backup",
#:params => "params",
#:observed => "observed",
#:autoshow => "autoshow",
#:popover => "slpopover",
# :main => "smart-listing",
# :controls_initialized => "smart-listing-controls-initialized",
# :confirmation => "confirmation",
# :id => "id",
# :href => "href",
# :callback_href => "callback-href",
# :max_count => "max-count",
# :item_count => "item-count",
# :inline_edit_backup => "smart-listing-edit-backup",
# :params => "params",
# :observed => "observed",
# :autoshow => "autoshow",
# :popover => "slpopover",
}

config.constants :selectors, {
#:item_action_destroy => "a.destroy",
#:edit_cancel => "button.cancel",
#:row => "tr",
#:head => "thead",
#:filtering_icon => "i"
#:filtering_button => "button",
#:filtering_icon => "button span",
#:filtering_input => ".filter input",
#:pagination_count => ".pagination-per-page .count",
# :item_action_destroy => "a.destroy",
# :edit_cancel => "button.cancel",
# :row => "tr",
# :head => "thead",
# :filtering_icon => "i"
# :filtering_button => "button",
# :filtering_icon => "button span",
# :filtering_input => ".filter input",
# :pagination_count => ".pagination-per-page .count",
}

config.constants :element_templates, {
#:row => "<tr />",
# :row => "<tr />",
}

config.constants :bootstrap_commands, {
#:popover_destroy => "destroy", # Bootstrap 4 requries dipsose instead of destroy
# :popover_destroy => "destroy", # Bootstrap 4 requries dipsose instead of destroy
}
end
20 changes: 12 additions & 8 deletions lib/generators/smart_listing/views_generator.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# frozen_string_literal: true

require 'rails/generators'

module SmartListing
module Generators
class ViewsGenerator < Rails::Generators::Base
source_root File.expand_path('../../../../app/views/smart_listing', __FILE__)
source_root File.expand_path('../../../app/views/smart_listing', __dir__)

def self.banner #:nodoc:
<<-BANNER.chomp
rails g smart_listing:views
def self.banner
<<~BANNER.chomp
rails g smart_listing:views
Copies all smart listing partials templates to your application.
BANNER
Copies all smart listing partials templates to your application.
BANNER
end

desc ''
def copy_views
filename_pattern = File.join self.class.source_root, "*.html.erb"
Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
filename_pattern = File.join(self.class.source_root, '*.html.erb')
Dir.glob(filename_pattern).map { |f| File.basename f }.each do |f|
copy_file f, "app/views/smart_listing/#{f}"
end
end
Expand Down
8 changes: 6 additions & 2 deletions lib/smart_listing.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# frozen_string_literal: true

require 'smart_listing/config'
require 'smart_listing/engine'
# require external dependencies
require 'kaminari'

# require internal dependencies
require_relative 'smart_listing/engine'
require_relative 'smart_listing/config'
require_relative 'smart_listing/version'

# Fix parsing nested params
module Kaminari
module Helpers
Expand Down

0 comments on commit 4450ee6

Please sign in to comment.