rails_accordion 0.1.5.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/lib/generators/rails_accordion/install_generator.rb +13 -0
- data/lib/generators/rails_accordion/templates/accordion_controller.js.tt +38 -0
- data/lib/rails_accordion/accordion.rb +13 -0
- data/lib/rails_accordion/accordion_item.rb +0 -0
- data/lib/rails_accordion/components/accordion_component.rb +23 -0
- data/lib/rails_accordion/components/item_component.rb +40 -0
- data/lib/rails_accordion/version.rb +5 -0
- data/lib/rails_accordion.rb +23 -0
- data/lib/tasks/rails_accordion_tasks.rake +4 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ff481f08fc6909483bcb8be004d23f34871b03743beed4dad4079c039ee61732
|
4
|
+
data.tar.gz: 875095bdc66e3ccd30f9b133a6f66a3c46ac830b29b783a80ece2cd1d281b49a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9fc5c914c9826cb62238cfd6e826404b8e864a6d025682fe15fb68cf4c1d925c79eb4b8b4829f33fccc243b4ae2a1aeaf88f8ab854920754fce84645f63d6048
|
7
|
+
data.tar.gz: a543be6a95a177af5312e693bc7d4789a8b62ed35f9f7c57de33eceac0cd50978a49c8b3d0af939e5b7427d800ba6865e21277b6a6c772e758ddd52c586d509a
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# RailsAccordion
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_accordion`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_accordion. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rails_accordion/blob/master/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the RailsAccordion project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails_accordion/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module RailsAccordion
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def copy_stimulus_controller
|
9
|
+
copy_file 'accordion_controller.js.tt', 'app/javascript/controllers/accordion_controller.js'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
connect() {
|
5
|
+
this.initAccordion();
|
6
|
+
}
|
7
|
+
|
8
|
+
initAccordion() {
|
9
|
+
const $toggles = $(this.element).find('.accordion_toggle');
|
10
|
+
|
11
|
+
const removeAllActiveClass = () => {
|
12
|
+
$toggles.each((el) => {
|
13
|
+
const $parent = $(el).parent();
|
14
|
+
$parent.removeClass('active');
|
15
|
+
$parent.find('.accordion_content').height(0);
|
16
|
+
});
|
17
|
+
};
|
18
|
+
|
19
|
+
$toggles.on('touch click', (e) => {
|
20
|
+
const $toggle = $(e.currentTarget);
|
21
|
+
const $parent = $toggle.parent();
|
22
|
+
const $content = $parent.find('.accordion_content');
|
23
|
+
|
24
|
+
if (!$parent.hasClass('active')) {
|
25
|
+
removeAllActiveClass();
|
26
|
+
$parent.addClass('active');
|
27
|
+
$content.height('100%');
|
28
|
+
} else {
|
29
|
+
$parent.removeClass('active');
|
30
|
+
$content.css({ height: '0px' });
|
31
|
+
}
|
32
|
+
});
|
33
|
+
}
|
34
|
+
|
35
|
+
afterReflex() {
|
36
|
+
this.initAccordion();
|
37
|
+
}
|
38
|
+
}
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsAccordion
|
4
|
+
class AccordionComponent < ViewComponent::Base
|
5
|
+
def initialize(**args)
|
6
|
+
@args = args.presence || {}
|
7
|
+
set_controller
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
content_tag :div, **@args do
|
12
|
+
content
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def set_controller
|
19
|
+
@args[:data] ||= {}
|
20
|
+
@args[:data][:controller] = [@args[:data][:controller], "accordion"].compact.join(' ')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsAccordion
|
4
|
+
class ItemComponent < ViewComponent::Base
|
5
|
+
renders_one :body
|
6
|
+
renders_one :header
|
7
|
+
|
8
|
+
def initialize(**args)
|
9
|
+
@args = args.presence || {}
|
10
|
+
|
11
|
+
set_root_classes
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
content_tag :div, **@args do
|
16
|
+
header_component + body_component
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def header_component
|
23
|
+
content_tag :div, header, class: "accordion_toggle"
|
24
|
+
end
|
25
|
+
|
26
|
+
def body_component
|
27
|
+
if body?
|
28
|
+
content_tag :div, class: 'accordion_content' do
|
29
|
+
content_tag :div, body, class: 'accordion_content-container p-2'
|
30
|
+
end
|
31
|
+
else
|
32
|
+
content_tag(:div, nil, class: "hidden")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_root_classes
|
37
|
+
@args[:class] = [@args[:class], "accordion_item"].compact.join(' ')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "rails_accordion/version"
|
4
|
+
require_relative "rails_accordion/components/accordion_component"
|
5
|
+
require_relative "rails_accordion/components/item_component"
|
6
|
+
|
7
|
+
module RailsAccordion
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class Railtie < Rails::Railtie
|
11
|
+
ActiveSupport.on_load :action_view do
|
12
|
+
include RailsAccordion
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def accordion(**args, &block)
|
17
|
+
render RailsAccordion::AccordionComponent.new(**args), &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def accordion_item(**args, &block)
|
21
|
+
render RailsAccordion::ItemComponent.new(**args), &block
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_accordion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5.pre.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ahmadshoh Nasrullozoda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: stimulus-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: view_component
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.52'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.52'
|
41
|
+
description: rails_accordion is in development.
|
42
|
+
email:
|
43
|
+
- tajbrains@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/generators/rails_accordion/install_generator.rb
|
51
|
+
- lib/generators/rails_accordion/templates/accordion_controller.js.tt
|
52
|
+
- lib/rails_accordion.rb
|
53
|
+
- lib/rails_accordion/accordion.rb
|
54
|
+
- lib/rails_accordion/accordion_item.rb
|
55
|
+
- lib/rails_accordion/components/accordion_component.rb
|
56
|
+
- lib/rails_accordion/components/item_component.rb
|
57
|
+
- lib/rails_accordion/version.rb
|
58
|
+
- lib/tasks/rails_accordion_tasks.rake
|
59
|
+
homepage: https://tajbrains.com
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
homepage_uri: https://tajbrains.com
|
64
|
+
source_code_uri: https://github.com/Tajbrains/rails_accordion
|
65
|
+
changelog_uri: https://github.com/Tajbrains/rails_accordion/blob/master/CHANGELOG.md
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.6.0
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.1
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.0.1
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: rails_accordion is in development.
|
85
|
+
test_files: []
|