sliders 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 68fe0a1c6326b7c9f44c3d68ac87df690a371cedd006ad9ea63e8928381eb71d
4
+ data.tar.gz: 8c6312ebe8667e00e36af23cff3bba3e016003d5d38d369e3fd4f4bb42d3db30
5
+ SHA512:
6
+ metadata.gz: a30d308fabbf05242057bc284e4b107e6f788e47160c45adbd56bddd90d1d4569e56301d48b4931ae1147bf3e43b7f0ffd70dc42b3aa4139d60edf4d03c5c646
7
+ data.tar.gz: b7df7a627e6ba3916bc9e9a356ea2037171e6f37acd3d3ad148caefa14841aa1f50b548726cf2596ca97c9a10b358467fb75bd4a8e3c855708ffcec8fad6704b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Simon Træls Ravn
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,75 @@
1
+ # 🍔 Sliders
2
+ Sliders are mini "app-folders" for grouping related code in your Rails application.
3
+
4
+ *Like a slider is not really a burger 🍔 this is not really app folders 😉*
5
+
6
+ Some times you have bundles of code in your app that is related to some specific feature.
7
+ Extracting to a gem is not really an option as the feature is tightly integrated with the rest of the application. So how do you get a good structure of files in you application?
8
+
9
+ With `sliders` you get a namespace folder that groups all you files.
10
+
11
+ Going from:
12
+ ```plain
13
+ app/
14
+ ├─ controllers/
15
+ │ └─ my_feature/
16
+ │ ├─ first_controller.rb
17
+ │ └─ second_controller.rb
18
+ ├─ models/
19
+ │ └─ my_feature/
20
+ │ ├─ record_a.rb
21
+ │ └─ record_b.rb
22
+ ├─ jobs/
23
+ │ └─ my_feature/
24
+ │ └─ run_in_background_job.rb
25
+ └─ interactors/
26
+ └─ my_feature/
27
+ └─ important_feature_task.rb
28
+ ```
29
+
30
+ To:
31
+ ```plain
32
+ app/
33
+ └─ sliders/
34
+ └─ my_feature/
35
+ ├─ controllers/
36
+ │ ├─ first_controller.rb
37
+ │ └─ second_controller.rb
38
+ ├─ models/
39
+ │ ├─ record_a.rb
40
+ │ └─ record_b.rb
41
+ ├─ jobs/
42
+ │ └─ run_in_background_job.rb
43
+ └─ interactors/
44
+ └─ important_feature_task.rb
45
+ ```
46
+
47
+
48
+ ## Installation
49
+ Add this line to your application's Gemfile:
50
+
51
+ ```ruby
52
+ gem "sliders"
53
+ ```
54
+
55
+ And then execute:
56
+ ```bash
57
+ $ bundle
58
+ ```
59
+
60
+ ## Usage
61
+
62
+
63
+ ## Contributing
64
+ Contribution directions go here.
65
+
66
+ ### Generators missing
67
+ - view
68
+ - fixtures
69
+ - model (orm)
70
+ - jobs
71
+ - components
72
+ - ...
73
+
74
+ ## License
75
+ 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,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
File without changes
@@ -0,0 +1,22 @@
1
+ module FixSlidersViewPath
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_action :fix_slider_view_path
6
+ end
7
+
8
+ def fix_slider_view_path
9
+ Dir.glob("#{Rails.root}/app/sliders/*").each do |slice|
10
+ prepend_view_path ActionView::FileSystemResolver.new(slice + "/views/")
11
+ end
12
+ end
13
+
14
+ class_methods do
15
+ def local_prefixes
16
+ controller_file_path = Object.const_source_location(self.name).first
17
+ return super unless controller_file_path.include?("#{Rails.root}/app/sliders/")
18
+
19
+ [ controller_path, controller_path.gsub("#{self.name.split("::").first.underscore}/", "") ]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ ActiveSupport::Reloader.to_prepare do
2
+ # make controllers aware of sliders and adjust view path on slider controllers
3
+ ApplicationController.include FixSlidersViewPath
4
+ # reload sliders code and load list of sliders
5
+ Sliders.reload_sliders
6
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,11 @@
1
+ require "rails/generators/rails/controller/controller_generator"
2
+ module SlidersControllerGenerator
3
+ extend ActiveSupport::Concern
4
+
5
+ def create_controller_files
6
+ return super unless (class_path & Sliders.sliders).any?
7
+
8
+ template "controller.rb", File.join("app/sliders/", class_path[0], "controllers", class_path[1..], "#{file_name}_controller.rb")
9
+ end
10
+ end
11
+ Rails::Generators::ControllerGenerator.prepend SlidersControllerGenerator
@@ -0,0 +1,11 @@
1
+ require "rails/generators/rails/helper/helper_generator"
2
+ module SlidersHelperGenerator
3
+ extend ActiveSupport::Concern
4
+
5
+ def create_helper_files
6
+ return super unless (class_path & Sliders.sliders).any?
7
+
8
+ template "helper.rb", File.join("app/sliders/", class_path[0], "helpers", class_path[1..], "#{file_name}_helper.rb")
9
+ end
10
+ end
11
+ Rails::Generators::HelperGenerator.prepend SlidersHelperGenerator
@@ -0,0 +1,12 @@
1
+ require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
2
+ module SlidersScaffoldControllerGenerator
3
+ extend ActiveSupport::Concern
4
+
5
+ def create_controller_files
6
+ return super unless (controller_class_path & Sliders.sliders).any?
7
+
8
+ template_file = options.api? ? "api_controller.rb" : "controller.rb"
9
+ template template_file, File.join("app/sliders/", controller_class_path[0], "controllers", controller_class_path[1..], "#{controller_file_name}_controller.rb")
10
+ end
11
+ end
12
+ Rails::Generators::ScaffoldControllerGenerator.prepend SlidersScaffoldControllerGenerator
@@ -0,0 +1,4 @@
1
+ module Sliders
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Sliders
2
+ VERSION = "0.1.0"
3
+ end
data/lib/sliders.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "sliders/version"
2
+ require "sliders/engine"
3
+ require "rails/generators"
4
+ require "rails_ext/controller_generator"
5
+ require "rails_ext/scaffold_controller_generator"
6
+ require "rails_ext/helper_generator"
7
+
8
+ module Sliders
9
+ # Your code goes here...
10
+
11
+ def self.sliders
12
+ @sliders ||= []
13
+ end
14
+
15
+ def self.reload_sliders
16
+ @sliders = []
17
+ Dir.glob("#{Rails.root}/app/sliders/*").each do |slice|
18
+ next unless File.directory?(slice)
19
+
20
+ @sliders << slice.split("/").last
21
+ Dir.glob("#{slice}/*").each do |path|
22
+ Rails.autoloaders.main.collapse(path) unless File.file?(path)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sliders do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sliders
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Træls Ravn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-08-26 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: 7.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.2.1
27
+ description: Create app'ish folders to group your features.
28
+ email:
29
+ - traels@traels.it
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/sliders_manifest.js
38
+ - app/controllers/concerns/fix_sliders_view_path.rb
39
+ - config/initializers/autoloader.rb
40
+ - config/routes.rb
41
+ - lib/rails_ext/controller_generator.rb
42
+ - lib/rails_ext/helper_generator.rb
43
+ - lib/rails_ext/scaffold_controller_generator.rb
44
+ - lib/sliders.rb
45
+ - lib/sliders/engine.rb
46
+ - lib/sliders/version.rb
47
+ - lib/tasks/sliders_tasks.rake
48
+ homepage: https://github.com/traels-it/sliders
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/traels-it/sliders
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.5.11
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Create app'ish folders to group your features.
72
+ test_files: []