bulma-phlex-rails 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a85eb64e11f1a1cd0649c716644d77c998f8eca5586702134d05b9ba19f742f9
4
- data.tar.gz: a5913c8af7d86296bb9fe8749ed1cd2bf95bbcbad68a96ece2f6219d229d227e
3
+ metadata.gz: 9ccde325abe028d8ab12fb8dfbcd754814274554029fffe1c443c21d0936c6e1
4
+ data.tar.gz: 0e526e0539626fa8b17780e9ce1db8edc2d81b68c4808fa0fcb108dad44e1944
5
5
  SHA512:
6
- metadata.gz: a7bad96383be09de73ba745775ab5ef114d843f232eacf18f8f7b7a8242819d02dfbbd889bdc052bbdf05d8d602fd85138d5ba3aa7f130d1f1475ed3e923f804
7
- data.tar.gz: 72f5562ee7c4c5774ec3c9158f37ec8b91b349bed77f64852d5c7b4fdcf8f563d1fa3ae926ae09bc0dc072b58a285c218c198a847d2240abeb1ad8e49990dd44
6
+ metadata.gz: fca248f599cd3f0793a37864c791e451b8e9019639e093dea13b27dc5a5443dc21b85959201f14763a896edf8f094c22907fd45854b74c6302dce3f5712430e0
7
+ data.tar.gz: 0e7e6196221edf59fb6c1303d4ef0e74d30522dfbb37e9c7c2ff8a15f3e90f33a6c3f65c142776ce1f9a53d155ab8e6860c909335bafe9ccd464e25c11b3d64e
@@ -0,0 +1,38 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ /*
4
+ To use this Stimulus controller, add the controller to your dropdown container
5
+ and the action to your dropdown button:
6
+
7
+ <div class="dropdown" data-controller="bulma_phlex--dropdown">
8
+ <button data-action="bulma_phlex--dropdown#toggle">
9
+ Dropdown
10
+ </button>
11
+ <div class="dropdown-menu">...</div>
12
+ </div>
13
+
14
+ This will toggle the dropdown menu when the button is clicked.
15
+ */
16
+
17
+ export default class extends Controller {
18
+ connect() {
19
+ this.closeHandler = this.close.bind(this);
20
+ document.addEventListener("click", this.closeHandler);
21
+ }
22
+
23
+ disconnect() {
24
+ if (this.closeHandler) {
25
+ document.removeEventListener("click", this.closeHandler);
26
+ this.closeHandler = null;
27
+ }
28
+ }
29
+
30
+ toggle(event) {
31
+ event.stopPropagation();
32
+ this.element.classList.toggle("is-active");
33
+ }
34
+
35
+ close(_event) {
36
+ this.element.classList.remove("is-active");
37
+ }
38
+ }
@@ -0,0 +1,82 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["fileInput", "fileList"]
5
+
6
+ acceptValues = []
7
+
8
+ connect() {
9
+ this.show()
10
+ this.#parseAcceptAttribute()
11
+ }
12
+
13
+ show() {
14
+ const preview = this.fileListTarget;
15
+ this.#clear(preview)
16
+
17
+ const curFiles = this.fileInputTarget.files;
18
+ if (curFiles.length === 0) {
19
+ const para = document.createElement("p")
20
+ para.textContent = "No files currently selected for upload"
21
+ preview.appendChild(para)
22
+ } else {
23
+ const list = document.createElement("ul")
24
+ preview.appendChild(list)
25
+
26
+ for (const file of curFiles) {
27
+ const listItem = document.createElement("li")
28
+ listItem.textContent = this.#fileTextContent(file)
29
+ list.appendChild(listItem);
30
+ }
31
+ }
32
+ }
33
+
34
+ #clear(preview) {
35
+ while (preview.firstChild) {
36
+ preview.removeChild(preview.firstChild);
37
+ }
38
+ }
39
+
40
+ #fileTextContent(file) {
41
+ if (this.#validFileType(file)) {
42
+ return this.#fileInfo(file);
43
+ } else {
44
+ return `File name ${file.name}: Not a valid file type. Update your selection.`;
45
+ }
46
+ }
47
+
48
+ #validFileType(file) {
49
+ // If no accept attribute is specified, accept all files
50
+ if (this.acceptValues.length === 0) {
51
+ return true
52
+ }
53
+
54
+ const fileExtension = `.${file.name.split('.').pop().toLowerCase()}`
55
+ const fileMimeType = file.type.toLowerCase()
56
+
57
+ // Check if the file matches any of the accept criteria
58
+ return this.acceptValues.some(acceptValue => {
59
+ if (acceptValue.startsWith('.')) {
60
+ // Check file extension (e.g. ".jpg")
61
+ return acceptValue.toLowerCase() === fileExtension
62
+ } else if (acceptValue.includes('/*')) {
63
+ // Check MIME type with wildcard (e.g. "image/*")
64
+ const acceptGroup = acceptValue.split('/')[0]
65
+ return fileMimeType.startsWith(`${acceptGroup}/`)
66
+ } else {
67
+ // Check specific MIME type (e.g. "image/jpeg")
68
+ return acceptValue === fileMimeType
69
+ }
70
+ })
71
+ }
72
+
73
+ #fileInfo(file) {
74
+ return `${file.name} (${file.size} bytes)`
75
+ }
76
+
77
+ #parseAcceptAttribute() {
78
+ if (this.fileInputTarget.accept) {
79
+ this.acceptValues = this.fileInputTarget.accept.split(',').map(type => type.trim())
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,10 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = [ "burger", "menu" ]
5
+
6
+ toggle(_event) {
7
+ this.burgerTarget.classList.toggle('is-active');
8
+ this.menuTarget.classList.toggle('is-active');
9
+ }
10
+ }
@@ -0,0 +1,37 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ export default class extends Controller {
4
+ static targets = ["tab", "content"];
5
+
6
+ showTabContent(event) {
7
+ event.preventDefault();
8
+
9
+ const id = event.currentTarget.dataset.tabContent;
10
+ this.showTabAndContentForId(id);
11
+ }
12
+
13
+ showTabAndContentForId(id) {
14
+ this.manageTabs(id);
15
+ this.manageContent(id);
16
+ }
17
+
18
+ manageTabs(id) {
19
+ this.tabTargets.forEach((tab) => {
20
+ if (tab.dataset.tabContent === id) {
21
+ tab.classList.add("is-active");
22
+ } else {
23
+ tab.classList.remove("is-active");
24
+ }
25
+ });
26
+ }
27
+
28
+ manageContent(id) {
29
+ this.contentTargets.forEach((content) => {
30
+ if (content.id === id) {
31
+ content.classList.remove("is-hidden");
32
+ } else {
33
+ content.classList.add("is-hidden");
34
+ }
35
+ });
36
+ }
37
+ }
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ pin_all_from File.expand_path("../app/javascript/controllers/bulma_phlex", __dir__), under: "controllers/bulma_phlex"
@@ -1,7 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bulma_phlex_rails/engine"
4
-
5
- # Create namespace for engine.
6
- module BulmaPhlexRails
7
- end
3
+ require "bulma_phlex/rails"
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/engine"
4
+
5
+ module BulmaPhlex
6
+ module Rails
7
+ # Rails Engine for BulmaPhlex
8
+ class Engine < ::Rails::Engine
9
+ initializer "bulma_phlex.rails.importmap", before: "importmap" do |app|
10
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
11
+ end
12
+
13
+ initializer "bulma_phlex.rails.assets" do |app|
14
+ app.config.assets.paths << root.join("app/javascript")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BulmaPhlex
4
+ module Rails
5
+ # # Card Helper
6
+ #
7
+ # This module provides method `turbo_frame_content` to create a card with a turbo frame as its content.
8
+ module CardHelper
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ include Phlex::Rails::Helpers::TurboFrameTag
13
+ end
14
+
15
+ # Renders a Bulma-styled card with a Turbo Frame as its content. This uses the same signatures as
16
+ # `turbo_frame_tag`, with the addition of two optional attributes: `pending_message` and `pending_icon`.
17
+ #
18
+ # The two pending attributes have the following defaults:
19
+ # - pending_message: "Loading..."
20
+ # - pending_icon: "fas fa-spinner fa-pulse"
21
+ def turbo_frame_content(*ids, src: nil, target: nil, **attributes)
22
+ pending_message = attributes.delete(:pending_message) || "Loading..."
23
+ pending_icon = attributes.delete(:pending_icon) || "fas fa-spinner fa-pulse"
24
+
25
+ content do
26
+ turbo_frame_tag ids, src: src, target: target, **attributes do
27
+ span(class: "icon") { i class: pending_icon }
28
+ span { plain pending_message }
29
+ end
30
+ # rescue StandardError => e
31
+ # puts "Error in turbo_frame_content: #{e.message}"
32
+ # puts e.args
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BulmaPhlex
4
+ module Rails
5
+ # # Table Helper
6
+ #
7
+ # This module provides method `amount_column` to create an amount column in a table.
8
+ module TableHelper
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ include Phlex::Rails::Helpers::NumberToCurrency
13
+ end
14
+
15
+ def amount_column(header, currency: {}, **html_attributes, &content)
16
+ html_attributes[:class] = [html_attributes[:class], "has-text-right"].compact.join(" ")
17
+
18
+ column(header, **html_attributes) do |row|
19
+ number_to_currency(content.call(row), **currency)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BulmaPhlex
4
+ module Rails
5
+ VERSION = "0.2.1"
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view"
4
+ require "bulma-phlex"
5
+ require "phlex-rails"
6
+ require "zeitwerk"
7
+
8
+ module BulmaPhlex
9
+ # The Rails namespace provides Bulma Phlex components and helpers for integration with Ruby on Rails applications.
10
+ module Rails
11
+ end
12
+ end
13
+
14
+ loader = Zeitwerk::Loader.for_gem_extension(BulmaPhlex)
15
+ loader.collapse("#{__dir__}/rails/components")
16
+ loader.collapse("#{__dir__}/rails/helpers")
17
+ loader.setup
18
+
19
+ require "bulma_phlex/rails/engine"
20
+
21
+ # Rails-specific extensions to BulmaPhlex components
22
+ BulmaPhlex::Card.include(BulmaPhlex::Rails::CardHelper) if defined?(Turbo)
23
+ BulmaPhlex::Table.include(BulmaPhlex::Rails::TableHelper)
metadata CHANGED
@@ -1,14 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulma-phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: actionpack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: bulma-phlex
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.8.0
40
+ - !ruby/object:Gem::Dependency
41
+ name: phlex-rails
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '2.3'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '2.3'
54
+ - !ruby/object:Gem::Dependency
55
+ name: railties
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '7.2'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '7.2'
12
68
  description: Create forms with Bulma CSS framework styles using Phlex components in
13
69
  your Rails applications.
14
70
  email:
@@ -17,9 +73,17 @@ executables: []
17
73
  extensions: []
18
74
  extra_rdoc_files: []
19
75
  files:
76
+ - app/javascript/controllers/bulma_phlex/dropdown_controller.js
77
+ - app/javascript/controllers/bulma_phlex/file_input_display_controller.js
78
+ - app/javascript/controllers/bulma_phlex/navigation_bar_controller.js
79
+ - app/javascript/controllers/bulma_phlex/tabs_controller.js
80
+ - config/importmap.rb
20
81
  - lib/bulma-phlex-rails.rb
21
- - lib/bulma_phlex_rails/engine.rb
22
- - lib/bulma_phlex_rails/version.rb
82
+ - lib/bulma_phlex/rails.rb
83
+ - lib/bulma_phlex/rails/engine.rb
84
+ - lib/bulma_phlex/rails/helpers/card_helper.rb
85
+ - lib/bulma_phlex/rails/helpers/table_helper.rb
86
+ - lib/bulma_phlex/rails/version.rb
23
87
  homepage: https://github.com/RockSolt/bulma-phlex-rails
24
88
  licenses:
25
89
  - MIT
@@ -33,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
33
97
  requirements:
34
98
  - - ">="
35
99
  - !ruby/object:Gem::Version
36
- version: 3.2.0
100
+ version: '3.4'
37
101
  required_rubygems_version: !ruby/object:Gem::Requirement
38
102
  requirements:
39
103
  - - ">="
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BulmaPhlexRails
4
- class Engine # rubocop:disable Lint/EmptyClass
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BulmaPhlexRails
4
- VERSION = "0.1.0"
5
- end