catalogs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 578ee6b1d66a1950c1d44bba7c7079e6635474e13ce47db9094c714451c6c605
4
+ data.tar.gz: 2c9d181fe9aa495f70c9b3d219f99fdbefe2dc78bc53797d7ab2c8033c19f679
5
+ SHA512:
6
+ metadata.gz: fd39526a1605fa2715af8decd318b6a62b310db7ff57d334db0c1351c02828d5cab31e07a72fa8a8b1dcf7b494bad205474849ccc0357f8cbbda03c141f464b3
7
+ data.tar.gz: 145f8606f3788f73df8da459fb71581ee260e76f50b4673c562d9d12ee61e42349dd7ad2284821dda43757cba389e0517bdc3634a126d5a92f080b05adb14a1c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Eduardo Figarola
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Catalogs
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'catalogs'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install catalogs
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "bundler/setup"
5
+ rescue LoadError
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
+ end
8
+
9
+ require "rdoc/task"
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "Catalogs"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
17
+ end
18
+
19
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
20
+ load "rails/tasks/engine.rake"
21
+
22
+ load "rails/tasks/statistics.rake"
23
+
24
+ require "bundler/gem_tasks"
25
+
26
+ require "rake/testtask"
27
+
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << "test"
30
+ t.pattern = "test/**/*_test.rb"
31
+ t.verbose = false
32
+ end
33
+
34
+ task default: :test
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/catalogs .css
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class ApplicationController < ActionController::Base
5
+ protect_from_forgery with: :exception
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ module ApplicationHelper
5
+ end
6
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ module CatalogsHelper
5
+ def catalog_options_for_select(model, field)
6
+ return if model.nil? || field.nil?
7
+ memoized_variable_name = "@_options_for_#{model}_#{field}_#{I18n.locale}"
8
+
9
+ if instance_variable_defined?(memoized_variable_name)
10
+ return instance_variable_get(memoized_variable_name)
11
+ end
12
+
13
+ options = Catalogs::Catalog.where(model: model, field: field).pluck(:label, :value)
14
+
15
+ internationalized_options = options.map do |option|
16
+ [
17
+ I18n.t("catalogs.#{model}.#{field}.labels.#{option[0]}", default: option[0]),
18
+ I18n.t("catalogs.#{model}.#{field}.values.#{option[1]}", default: option[1])
19
+ ]
20
+ end
21
+
22
+ instance_variable_set(
23
+ "@_options_for_#{model}_#{field}_#{I18n.locale}",
24
+ internationalized_options
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class ApplicationJob < ActiveJob::Base
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class ApplicationMailer < ActionMailer::Base
5
+ default from: "from@example.com"
6
+ layout "mailer"
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class Catalog < ApplicationRecord
5
+ validates_presence_of :model, :field, :label, :value
6
+ validates_uniqueness_of :label, :value, scope: %i[model field]
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Catalogs</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "catalogs/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Catalogs::Engine.routes.draw do
2
+ end
@@ -0,0 +1,12 @@
1
+ class CreateCatalogsCatalogs < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :catalogs_catalogs do |t|
4
+ t.string :model, null: false
5
+ t.string :field, null: false
6
+ t.string :label, null: false
7
+ t.string :value, null: false
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
data/lib/catalogs.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "catalogs/engine"
4
+
5
+ module Catalogs
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Catalogs
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Catalogs
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ desc "Configure Application to use Catalogs Engine"
8
+
9
+ def include_engine_helper_methods
10
+ code = <<-RUBY
11
+ helper Catalogs::Engine.helpers
12
+ RUBY
13
+
14
+ inject_into_file(
15
+ "app/controllers/application_controller.rb",
16
+ after: "class ApplicationController < ActionController::Base\n"
17
+ ) do
18
+ code
19
+ end
20
+ end
21
+
22
+ def copy_locale_file
23
+ copy_file "catalogs.en.yml", "config/locales/catalogs.en.yml"
24
+ end
25
+
26
+ def copy_migrations
27
+ rake "catalogs:install:migrations"
28
+ end
29
+
30
+ def run_migrations
31
+ rake "db:migrate"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,8 @@
1
+ en:
2
+ catalogs:
3
+ model:
4
+ field:
5
+ labels:
6
+ key: value
7
+ values:
8
+ key: value
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :catalogs do
4
+ desc "Creates a Catalog record. Usage `rake catalogs:create model field label value`"
5
+ task create: :environment do
6
+ _, *args = ARGV
7
+
8
+ if args.size != 4
9
+ puts "Invalid number of arguments"
10
+ puts "You have to provide them in this order: model, field, label, value"
11
+ exit
12
+ end
13
+
14
+ Catalogs::Catalog.create(
15
+ model: args[0],
16
+ field: args[1],
17
+ label: args[2],
18
+ value: args[3]
19
+ )
20
+
21
+ exit
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catalogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eduardo Figarola
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '5'
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: sqlite3
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.4'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.4'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubocop
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.74'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.74'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-rails_config
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.7'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.7'
75
+ description: A way to improve your website dropdowns values in a standard way
76
+ email:
77
+ - eduardofigarola@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - MIT-LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - app/assets/config/catalogs_manifest.js
86
+ - app/assets/stylesheets/catalogs/application.css
87
+ - app/controllers/catalogs/application_controller.rb
88
+ - app/helpers/catalogs/application_helper.rb
89
+ - app/helpers/catalogs/catalogs_helper.rb
90
+ - app/jobs/catalogs/application_job.rb
91
+ - app/mailers/catalogs/application_mailer.rb
92
+ - app/models/catalogs/application_record.rb
93
+ - app/models/catalogs/catalog.rb
94
+ - app/views/layouts/catalogs/application.html.erb
95
+ - config/routes.rb
96
+ - db/migrate/20190919172839_create_catalogs_catalogs.rb
97
+ - lib/catalogs.rb
98
+ - lib/catalogs/engine.rb
99
+ - lib/catalogs/version.rb
100
+ - lib/generators/catalogs/install_generator.rb
101
+ - lib/generators/catalogs/templates/catalogs.en.yml
102
+ - lib/tasks/catalogs_tasks.rake
103
+ homepage: https://github.com/efigarolam/catalogs
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ allowed_push_host: https://rubygems.org
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Rails Catalogs Plugin
127
+ test_files: []