From 8138c1746b9307ce3ae909e1f155e06f0ded9973 Mon Sep 17 00:00:00 2001 From: Leonid Medovyy Date: Fri, 14 Apr 2023 07:05:20 -0700 Subject: [PATCH 1/3] rubocop updates --- Gemfile.lock | 2 +- lib/install/rapid_ui.rb | 4 ++-- lib/rapid_ui/component.rb | 13 +++++++------ lib/rapid_ui/display.rb | 2 +- lib/rapid_ui/helpers.rb | 2 +- lib/rapid_ui/utilities.rb | 2 +- lib/rapid_ui/version.rb | 2 +- lib/tasks/rapid_ui.rake | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 475318f..5dda33c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rapid_ui (1.1.1) + rapid_ui (1.2.0) view_component GEM diff --git a/lib/install/rapid_ui.rb b/lib/install/rapid_ui.rb index a90d4e4..4408dba 100644 --- a/lib/install/rapid_ui.rb +++ b/lib/install/rapid_ui.rb @@ -1,5 +1,5 @@ RapidUi.configure do |config| - config.ui_file = Rails.root.join('config/ui.yml') + config.ui_file = Rails.root.join("config/ui.yml") end -RapidUi.boot \ No newline at end of file +RapidUi.boot diff --git a/lib/rapid_ui/component.rb b/lib/rapid_ui/component.rb index 5bd871c..1522bd0 100644 --- a/lib/rapid_ui/component.rb +++ b/lib/rapid_ui/component.rb @@ -1,19 +1,21 @@ module Ui # responsible for the out building of the component class Component - attr_accessor :action, :action_attr, :alt, :css_class, :data, :id, :img, :method, :name_attr, :placeholder, :rows, :style, :tag, :text, :title, :type, :url, :value, :rel + attr_accessor :action, :action_attr, :alt, :css_class, :data, :id, :img, :method, :name_attr, :placeholder, :rows, + :style, :tag, :text, :title, :type, :url, :value, :rel def initialize(settings) @settings = settings set_defaults build_component - transpose_settings %w[action_attr alt data id img method name_attr placeholder rows style tag text title type url value rel] + transpose_settings %w[action_attr alt data id img method name_attr placeholder rows style tag text title type url + value rel] end # sets component defaults def set_defaults @data = nil - @css_class = '' + @css_class = "" end # builds out the component @@ -29,13 +31,12 @@ def build_component # removes the ui class if the switch is set to false def build_ui - add_class 'ui' unless (@settings.key?(:ui) && @settings[:ui] == false) + add_class "ui" unless @settings.key?(:ui) && @settings[:ui] == false end - # adds dynamic class to the component is the switch is set to true def build_dynamic - add_class 'dynamic' if (@settings.key?(:dynamic) && @settings[:dynamic]) + add_class "dynamic" if @settings.key?(:dynamic) && @settings[:dynamic] end # builds out css class for the component diff --git a/lib/rapid_ui/display.rb b/lib/rapid_ui/display.rb index 8cf4bed..d9688b8 100644 --- a/lib/rapid_ui/display.rb +++ b/lib/rapid_ui/display.rb @@ -6,7 +6,7 @@ class Display < ActionView::Base include ViewComponent def initialize - RapidUi.configuration.ui_hash['ui'].each do |ui_element| + RapidUi.configuration.ui_hash["ui"].each do |ui_element| define_singleton_method ui_element[0].to_s do |args = {}| # for convenience we allow people to only pass a class string # it is the same as setting a class diff --git a/lib/rapid_ui/helpers.rb b/lib/rapid_ui/helpers.rb index 1a0e36c..633d26b 100644 --- a/lib/rapid_ui/helpers.rb +++ b/lib/rapid_ui/helpers.rb @@ -11,4 +11,4 @@ def ux Ui::Display.instance end end -end \ No newline at end of file +end diff --git a/lib/rapid_ui/utilities.rb b/lib/rapid_ui/utilities.rb index 972fde1..04c8a06 100644 --- a/lib/rapid_ui/utilities.rb +++ b/lib/rapid_ui/utilities.rb @@ -9,7 +9,7 @@ def initialize end def defaults(component:) - @config['ui'][component.to_s] + @config["ui"][component.to_s] end end end diff --git a/lib/rapid_ui/version.rb b/lib/rapid_ui/version.rb index a3c8fda..46dbe8d 100644 --- a/lib/rapid_ui/version.rb +++ b/lib/rapid_ui/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RapidUi - VERSION = "1.1.1" + VERSION = "1.2.0" end diff --git a/lib/tasks/rapid_ui.rake b/lib/tasks/rapid_ui.rake index 96dd3b8..90569b0 100644 --- a/lib/tasks/rapid_ui.rake +++ b/lib/tasks/rapid_ui.rake @@ -19,4 +19,4 @@ namespace :rapid_ui do puts "----------------------------------------" puts "Rapid Ui installed." end -end \ No newline at end of file +end From 3ee6a871868af4ab166f4d70e75eceee5a0f4156 Mon Sep 17 00:00:00 2001 From: Leonid Medovyy Date: Fri, 14 Apr 2023 09:16:49 -0700 Subject: [PATCH 2/3] upgrading stimulus & adding shortcuts --- lib/install/wrapper_component.rb | 6 ++-- lib/rapid_ui/component.rb | 49 ++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/lib/install/wrapper_component.rb b/lib/install/wrapper_component.rb index 40375db..7c6f46a 100644 --- a/lib/install/wrapper_component.rb +++ b/lib/install/wrapper_component.rb @@ -36,15 +36,17 @@ def tag_arguments arguments[:type] = @component.type arguments[:rows] = @component.rows arguments[:placeholder] = @component.placeholder + arguments[:step] = @component.step + arguments[:disabled] = @component.disabled arguments end - # retreives the default name from a hash + # retrieves the default name from a hash def default_name(default) default[0].to_sym end - # retreives the default value from a hash + # retrieves the default value from a hash def default_value(default) default[1] end diff --git a/lib/rapid_ui/component.rb b/lib/rapid_ui/component.rb index 1522bd0..c7cac00 100644 --- a/lib/rapid_ui/component.rb +++ b/lib/rapid_ui/component.rb @@ -1,15 +1,15 @@ module Ui # responsible for the out building of the component class Component - attr_accessor :action, :action_attr, :alt, :css_class, :data, :id, :img, :method, :name_attr, :placeholder, :rows, - :style, :tag, :text, :title, :type, :url, :value, :rel + attr_accessor :action, :action_attr, :alt, :css_class, :data, :id, :img, :method, :name_attr, :placeholder, :params, + :rows, :style, :tag, :text, :title, :type, :target, :url, :value, :rel, :step, :disabled def initialize(settings) @settings = settings set_defaults build_component transpose_settings %w[action_attr alt data id img method name_attr placeholder rows style tag text title type url - value rel] + value rel step disabled] end # sets component defaults @@ -26,6 +26,7 @@ def build_component build_responsiveness build_name build_default_class + apply_stimulus_shortcuts build_stimulus_props end @@ -44,7 +45,8 @@ def build_class add_class @settings[:class] if @settings.key?(:class) end - # builds out the reponsive css classes + # builds out the responsive css classes + # used by semantic-ui responsive classes def build_responsiveness add_class build_only if @settings.key?(:only) add_class build_size if @settings.key?(:size) @@ -55,7 +57,7 @@ def build_responsiveness end end - # builds out the name for the compnent + # builds out the name for the component def build_name return unless @settings.key?(:name) @@ -68,11 +70,19 @@ def build_default_class add_class @settings[:css_class] if @settings.key?(:css_class) end + def apply_stimulus_shortcuts + @settings[:controller] = @settings[:c] if @settings.key?(:c) + @settings[:action] = @settings[:a] if @settings.key?(:a) + @settings[:target] = @settings[:t] if @settings.key?(:t) + @settings[:params] = @settings[:p] if @settings.key?(:p) + end + # builds out stimulus.js shortcuts def build_stimulus_props add_data :controller, @settings[:controller] if @settings.key?(:controller) - add_data :target, @settings[:target] if @settings.key?(:target) add_data :action, @settings[:action] if @settings.key?(:action) + add_target_data @settings[:target] if @settings.key?(:target) + add_params_data @settings[:params] if @settings.key?(:params) end private @@ -130,5 +140,32 @@ def add_data(name, value) @settings[:data][name] = value end + + # goes through the target object and populates the data variables + def add_target_data(target_obj) + target_obj.keys.each do |target| + controller = target.to_s + target= target_obj[target] + + data_string = "#{controller}-target" + add_data(data_string, target) + end + end + + + # goes through the params object and populate the data variables + def add_params_data(params_obj) + params_obj.keys.each do |params_controller| + controller = params_controller.to_s + + params = params_obj[params_controller] + params.keys.each do |param| + param_value = params[param] + data_string = "#{controller}-#{param}-param" + + add_data(data_string, param_value) + end + end + end end end \ No newline at end of file From 47d45b394bdf0f17804523fe4add17dbe475b119 Mon Sep 17 00:00:00 2001 From: Leonid Medovyy Date: Fri, 14 Apr 2023 09:37:13 -0700 Subject: [PATCH 3/3] added values object and removed the action accessor since we are not accessing it directly --- lib/rapid_ui/component.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/rapid_ui/component.rb b/lib/rapid_ui/component.rb index c7cac00..2b73bf9 100644 --- a/lib/rapid_ui/component.rb +++ b/lib/rapid_ui/component.rb @@ -1,7 +1,7 @@ module Ui # responsible for the out building of the component class Component - attr_accessor :action, :action_attr, :alt, :css_class, :data, :id, :img, :method, :name_attr, :placeholder, :params, + attr_accessor :action_attr, :alt, :css_class, :data, :id, :img, :method, :name_attr, :placeholder, :params, :rows, :style, :tag, :text, :title, :type, :target, :url, :value, :rel, :step, :disabled def initialize(settings) @@ -75,6 +75,7 @@ def apply_stimulus_shortcuts @settings[:action] = @settings[:a] if @settings.key?(:a) @settings[:target] = @settings[:t] if @settings.key?(:t) @settings[:params] = @settings[:p] if @settings.key?(:p) + @settings[:values] = @settings[:v] if @settings.key?(:v) end # builds out stimulus.js shortcuts @@ -83,6 +84,7 @@ def build_stimulus_props add_data :action, @settings[:action] if @settings.key?(:action) add_target_data @settings[:target] if @settings.key?(:target) add_params_data @settings[:params] if @settings.key?(:params) + add_values_data @settings[:values] if @settings.key?(:values) end private @@ -167,5 +169,20 @@ def add_params_data(params_obj) end end end + + # goes through the values object and populate the data variables + def add_values_data(params_obj) + params_obj.keys.each do |params_controller| + controller = params_controller.to_s + + params = params_obj[params_controller] + params.keys.each do |param| + param_value = params[param] + data_string = "#{controller}-#{param}-value" + + add_data(data_string, param_value) + end + end + end end end \ No newline at end of file