bulmacomp 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: aba376c1b9ab6ef2532c7c313e28621f910c5959bf0285ce268e2936983ae0c1
4
+ data.tar.gz: 5462a699bc0b4fd5985674230ce986a3db9ed7cec16bcd2e098ab234e0793a72
5
+ SHA512:
6
+ metadata.gz: 9b4c29854e9bbb3dd9283b698633578d5b8b1c9b0b4868fa919ff392aa1690faa1f59c7cb4e031212d93ddbbde8a3ed966d624b1511dc84d4b83843d82e9d13f
7
+ data.tar.gz: 62b1d229680c06b33f75ae136c60999f4942e9f768d01f5ca33d56b1c53c327b33d6f74a6633e58a3835516b5ec16e96854324c4912ba22877f8e51162ec8826
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2023 MDreW
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
+ # Bulmacomp
2
+ [https://viewcomponent.org/](ViewComponent) collection for [https://bulma.io/](bulma) css framework
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 "bulmacomp"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install bulmacomp
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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ load 'rails/tasks/statistics.rake'
6
+
7
+ require 'bundler/gem_tasks'
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Make an html structure for a bulma breadcrumb
5
+ #
6
+ # @example Empty breadcrumb:
7
+ # render Bulmacomp::BreadcrumbComponent.new()
8
+ #
9
+ # <nav class="breadcrumb" aria-label="breadcrumbs">
10
+ # <ul>
11
+ # </ul>
12
+ # </nav>
13
+ #
14
+ # @example Empty breadcrumb with option:
15
+ # render Bulmacomp::BreadcrumbComponent.new(class: 'breadcrumb one', data: {entity: 'one'})
16
+ #
17
+ # <nav class="breadcrumb one" aria-label="breadcrumbs" data-entity='one'>
18
+ # <ul>
19
+ # </ul>
20
+ # </nav>
21
+ #
22
+ # @example Breadcrumb with list element:
23
+ # render Bulmacomp::BreadcrumbComponent.new(link_to('one','#'), link_to('two','#'))
24
+ # <nav class="breadcrumb" aria-label="breadcrumbs">
25
+ # <ul>
26
+ # <li><a href="#">one</a></li>
27
+ # <li><a href="#">two</a></li>
28
+ # </ul>
29
+ # </nav>
30
+ #
31
+ # @example Breadcrump with yield:
32
+ # render Bulmacomp::BreadcrumbComponent.new() do
33
+ # <li><a href="#">Bulma</a></li>
34
+ # end
35
+ #
36
+ # <nav class="breadcrumb" aria-label="breadcrumbs">
37
+ # <ul>
38
+ # <li><a href="#">Bulma</a></li>
39
+ # </ul>
40
+ # </nav>
41
+ class BreadcrumbComponent < ViewComponent::Base
42
+ # @param [Array<String>] list
43
+ # Any number of Objects to push into this collection
44
+ # @param [Hash] opts
45
+ # options to generate content
46
+ # @option opts [String] :*
47
+ # each other key going as tag option, default is class: 'breadcrumb', aria_label: 'breadcrumbs'
48
+ # @yield [optional] card content
49
+ def initialize(*list, **opts)
50
+ super
51
+ @list = list
52
+ @opts = { class: 'breadcrumb', aria: { label: 'breadcrumbs' } }.merge(opts)
53
+ end
54
+
55
+ # @return [String] html_safe breadcrumb
56
+ def call
57
+ tag.nav tag.ul(ul_content), **@opts
58
+ end
59
+
60
+ # @return [Text], safe join of list arguments and proc content
61
+ def ul_content
62
+ safe_join(@list.map { |e| tag.li(e) }.<<(content))
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Make an html structure for a bulma card
5
+ #
6
+ # @example empty card
7
+ # render Bulmacomp::BreadcrumbComponent.new()
8
+ #
9
+ # <div class="card"></div>
10
+ # @example cart with title and yeld content
11
+ # render Bulmacomp::BreadcrumbComponent.new(title: 'test') do
12
+ # <p>test content</p>
13
+ # end
14
+ #
15
+ # <div class="card">
16
+ # <div class="card-header">
17
+ # <div class="cart-header-title">test</div>
18
+ # </div>
19
+ # <div class="card-content">
20
+ # <div class="content"><p>test content</p>
21
+ # </div>
22
+ # </div>
23
+ class CardComponent < ViewComponent::Base
24
+ def initialize(title: nil, image: nil, footer: nil, **opts)
25
+ super
26
+ @title = title
27
+ @image = image
28
+ @footer = footer
29
+ @opts = { class: 'card' }.merge(opts)
30
+ end
31
+
32
+ # @return [String] html_safe card
33
+ def call
34
+ tag.div safe_join([card_title, card_image, card_content, card_footer]), **@opts
35
+ end
36
+
37
+ # @return [String] title section if :title is set
38
+ # @example
39
+ # Bulmacomp::BreadcrumbComponent.new(title: 'test').title
40
+ #
41
+ # <div class='card-header'><div class='card-header-title'>test</div></div>
42
+ def card_title
43
+ tag.div(tag.div(@title, class: 'card-header-title'), class: 'card-header') if @title
44
+ end
45
+
46
+ # return [String] image section if :image is set
47
+ # @example
48
+ # Bulmacomp::BreadcrumbComponent.new(title: 'test', image: 'test.jpg').image
49
+ #
50
+ # <div class='card-image'><img src='test.jpg' alt='test'></div>
51
+ def card_image
52
+ tag.div(tag.figure(image_tag(@image, alt: @title), class: 'image'), class: 'card-image') if @image
53
+ end
54
+
55
+ # return [String] content section if yield is present
56
+ # @example
57
+ # Bulmacomp::BreadcrumbComponent.new().title do
58
+ # test content
59
+ # end
60
+ #
61
+ # <div class="card-content"><div class="content"><p>test content</p></div>
62
+ def card_content
63
+ tag.div(tag.div(content, class: 'content'), class: 'card-content') if content
64
+ end
65
+
66
+ # return [String] footer section if a footer is present
67
+ # @example
68
+ # Bulmacomp::BreadcrumbComponent.new(footer: 'test').footer
69
+ #
70
+ # <div class='card-footer'>test</div>
71
+ def card_footer
72
+ tag.div @footer, class: 'card-footer' if @footer
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Make the html strucrure for a bulma menu
5
+ #
6
+ # @example Empty menu
7
+ # = render Bulmacomp::MenuComponent.new
8
+ #
9
+ # <aside class='menu'></aside>
10
+ #
11
+ # @example menu with title and entries
12
+ # title = 'Menu title'
13
+ # menu = [link_to('first entry', '#'), link_to('second entry', '#')
14
+ # render Bulmacomp::MenuComponent.new(title,menu)
15
+ #
16
+ # <aside class='menu'>
17
+ # <p class='menu-label'>Menu title</p>
18
+ # <ul>
19
+ # <li><a href='#'>first entry</li>
20
+ # <li><a href='#'>second entry<li>
21
+ # </ul>
22
+ # </aside>
23
+ #
24
+ # @example menu with title and annidate entries
25
+ # = render Bulmacomp::MenuComponent.new('Uno',['Due',['Tre','Quattro']])
26
+ #
27
+ # <aside class='menu'>
28
+ # <p class='menu-label'>Uno</p>
29
+ # <ul>
30
+ # <li>Due</li>
31
+ # <li>
32
+ # Tre
33
+ # <ul>
34
+ # <li>Quattro</li>
35
+ # </ul>
36
+ # <li>
37
+ # </ul>
38
+ # </aside>
39
+ #
40
+ # @example with conetent
41
+ # = render Bulmacomp::MenuComponent.new do
42
+ # %p some content
43
+ #
44
+ # <aside class='menu'>
45
+ # <p>some content</p>
46
+ # </aside>
47
+ #
48
+ # @example with mixed conetent (arguments before)
49
+ # = render Bulmacomp::MenuComponent.new('argument content',['argoument menu']) do
50
+ # %p yield content
51
+ #
52
+ # <aside class='menu'>
53
+ # <p class='menu-label'>argoument content</p>
54
+ # <ul>
55
+ # <li>argoument menu</li>
56
+ # </ul>
57
+ # <p>yield content</p>
58
+ # </aside>
59
+ #
60
+ class MenuComponent < ViewComponent::Base
61
+ # @param [Array<String,Array>] list
62
+ # each entry is used to generate menu entries throug {first_level} method
63
+ # @param [Hash] opts
64
+ # options to generate content
65
+ # @option opts [String] :*
66
+ # each key going as tag option, default is class: 'menu'
67
+ def initialize(*list, **opts)
68
+ super
69
+ @list = list
70
+ @opts = { class: 'menu' }.merge(opts)
71
+ end
72
+
73
+ # Generate an html safe string with full bulma menu.
74
+ # @return [String] html string menu
75
+ def call
76
+ tag.aside first_level(@list) + content, **@opts
77
+ end
78
+
79
+ # Generate a string with all bulma menu element from `values` param.
80
+ #
81
+ # Each element in `values` is mapped:
82
+ # * as `p.menu-title` tag if is not an Array
83
+ # * as {map_menu} if is an Array
84
+ # @return [String]
85
+ # @param [Array] values menu entries
86
+ # @example
87
+ # Bulmacomp::MenuComponent.new().first_level(['Uno',['Due','Tre']])
88
+ #
89
+ # <p class='menu-label'>Uno</p><ul><li>Due</li><li>Tre<li></ul>
90
+ def first_level(values = [])
91
+ safe_join(
92
+ values.map { |e| e.is_a?(Array) ? map_menu(e) : tag.p(e, class: 'menu-label') }
93
+ )
94
+ end
95
+
96
+ # Generate a string with the "real" menu entries (no title)
97
+ # from 'values' param. The menu entries are incapsulated in a ul tag
98
+ #
99
+ # Each element in 'values' is mapped:
100
+ # * as li tag if is not an Array
101
+ # * as {sub_menu} if is an Array
102
+ # @return [String]
103
+ # @param [Array] values menu entries
104
+ # @example
105
+ # Bulmacomp::MenuComponent.new().map_menu(['Uno',['Due','Tre']])
106
+ #
107
+ # <ul><li>Uno</li><li>Due<ul><li>Tre</li></ul></li></ul>
108
+ def map_menu(values = [])
109
+ tag.ul safe_join(values.map { |e| e.is_a?(Array) ? sub_menu(e) : tag.li(e) })
110
+ end
111
+
112
+ # Generate a string with sub-menu content from values params.
113
+ # The first array element is used as ancescor, other element
114
+ # are used to make the sub menu with {map_menu} method.
115
+ # @return [String]
116
+ # @param [Array] values sub-menu entries
117
+ # @example
118
+ # Bulmacomp::MenuComponent.new().sub_menu(['Uno',['Due','Tre']])
119
+ #
120
+ # <li>Uno<ul><li>Due</li><li>Tre</li></ul></li>
121
+ def sub_menu(values = [])
122
+ tag.li safe_join([values.shift, map_menu(values)])
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Make an html structure for a bulma breadcrumb
5
+ #
6
+ # @example Empty modal:
7
+ # = render Bulmacomp::PanelComponent.new()
8
+ #
9
+ # <div class="modal">
10
+ # <div class="modal-background"></div>
11
+ # <div class="modal-content"></div>
12
+ # <button class="modal-close is-large" aria-label="close"></button>
13
+ # </div>
14
+ #
15
+ # @example Modal with content:
16
+ # = render Bulmacomp::PanelComponent.new() do
17
+ # %p some content
18
+ #
19
+ # <div class="modal">
20
+ # <div class="modal-background"></div>
21
+ # <div class="modal-content"><p>Some content</p></div>
22
+ # <button class="modal-close is-large" aria-label="close"></button>
23
+ # </div>
24
+ class ModalComponent < ViewComponent::Base
25
+ # @param [Hash] opts options to generate content
26
+ # @option opts [String] :* each key going as tag option, default is class: 'modal'
27
+ # @yield [optional] modal content
28
+ def initialize(**opts)
29
+ super
30
+ @opts = { class: 'modal' }.merge opts
31
+ end
32
+
33
+ # return [String] html_safe generated bulma modal
34
+ def call
35
+ content_tag :div, safe_join([
36
+ tag.div(class: 'modal-background'),
37
+ tag.div(content, class: 'modal-content'),
38
+ tag.button(class: 'modal-close is-large', aria_label: 'close')
39
+ ]), **@opts
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Make an html structure for a bulma navbar
5
+ # @example Empty navbar:
6
+ # = render Bulmacomp::NavbarComponent.new()
7
+ #
8
+ # <nav class="navbar" role="navigation" aria-label="main navigation">
9
+ # <div class="navbar-brand">
10
+ # <a class="navbar-item" href="/"></a>
11
+ #
12
+ # <a role="button" class="navbar-burger" aria-label="menu"
13
+ # aria-expanded="false" data-target="navbarBasicExample" data_action="page#toggleMenu">
14
+ # <span aria-hidden="true"></span>
15
+ # <span aria-hidden="true"></span>
16
+ # <span aria-hidden="true"></span>
17
+ # </a>
18
+ # </div>
19
+ # <div class="navbar-menu"></div>
20
+ # </nav>
21
+ # @example full navbar:
22
+ # = render Bulmacomp::NavbarComponent.new(brand: 'Title') do
23
+ # <div class="navbar-start"><a href="/" class="navbar-item">Home</a>
24
+ #
25
+ # <nav class="navbar" role="navigation" aria-label="main navigation">
26
+ # <div class="navbar-brand">
27
+ # <a class="navbar-item" href="/">Title</a>
28
+ #
29
+ # <a role="button" class="navbar-burger" aria-label="menu"
30
+ # aria-expanded="false" data-target="navbarBasicExample" data_action="page#toggleMenu">
31
+ # <span aria-hidden="true"></span>
32
+ # <span aria-hidden="true"></span>
33
+ # <span aria-hidden="true"></span>
34
+ # </a>
35
+ # </div>
36
+ # <div class="navbar-menu"><div class="navbar-start"><a href="/" class="navbar-item">Home</a></div>
37
+ # </nav>
38
+ class NavbarComponent < ViewComponent::Base
39
+ # @param [Hash] opts
40
+ # to generate content
41
+ # @option opts [String] :brand
42
+ # navbar brand content
43
+ # @option opts [String] :*
44
+ # each other key going as tag option, default is
45
+ # class: 'navbar', aria_label: 'main navigation', aria_role: 'navigation'
46
+ # @yield [optional] navbar content
47
+ def initialize(brand: nil, **opts)
48
+ super
49
+ @brand = brand
50
+ @opts = { class: 'navbar', aria: { role: 'navigation', label: 'main navigation' } }.merge(opts)
51
+ end
52
+
53
+ # @return [String] html_safe navbar
54
+ def call
55
+ tag.nav safe_join([navbar_brand, navbar_menu]), @opts
56
+ end
57
+
58
+ # @return [String] html_safe navbar-brand tag
59
+ def navbar_brand
60
+ tag.div safe_join([link_to(@brand, root_path, data_turbo_frame: 'yield', class: 'navbar-item'), navbar_burger]),
61
+ class: 'navbar-brand'
62
+ end
63
+
64
+ # @return [String] html_safe navbar-menu tag
65
+ def navbar_menu
66
+ tag.div(content, class: 'navbar-menu')
67
+ end
68
+
69
+ # return [String] html_safe navbar-burger link
70
+ def navbar_burger
71
+ tag.a tag.span(aria_hidden: true) * 3, class: 'navbar-burger', aria_label: 'menu', aria_expanded: 'false',
72
+ data_action: 'page#toggleMenu'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Make an html structure for a bulma breadcrumb
5
+ #
6
+ # @example Empty panel:
7
+ # render Bulmacomp::PanelComponent.new()
8
+ #
9
+ # <nav class="panel">
10
+ # </nav>
11
+ #
12
+ # @example panel with option:
13
+ # = render Bulmacomp::PanelComponent.new(title: 'test title') do
14
+ # <a class="panel-block is-active">
15
+ # <span class="panel-icon"><i class="fas fa-book" aria-hidden="true"></i></span>
16
+ # bulma
17
+ # </a>
18
+ #
19
+ # <nav class="panel">
20
+ # <p class="panel-heading">test title</p>
21
+ # <a class="panel-block is-active">
22
+ # <span class="panel-icon"><i class="fas fa-book" aria-hidden="true"></i></span>
23
+ # bulma
24
+ # </a>
25
+ # </nav>
26
+ class PanelComponent < ViewComponent::Base
27
+ # @param [Hash] opts
28
+ # options to generate content
29
+ # @option opts [String] :title
30
+ # panel title
31
+ # @option opts [String] :*
32
+ # each other key going as tag option, default is class: 'breadcrumb', aria_label: 'breadcrumbs'
33
+ # @yield [optional]
34
+ # panel content
35
+ def initialize(title: nil, **opts)
36
+ super
37
+ @title = title
38
+ @opts = opts
39
+ @opts[:class] = 'panel' unless @opts[:class]
40
+ end
41
+
42
+ # return [String] html_safe generated bulma panel
43
+ def call
44
+ content_tag :nav, safe_join([title, content]), **@opts
45
+ end
46
+
47
+ # return [String] html_safe generated panel title
48
+ def title
49
+ tag.p @title, class: 'panel-heading' if @title
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ # Bulmacomp Engine, load the isolate namespace Bulmacomp
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Bulmacomp
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulmacomp
4
+ VERSION = '0.1.0'
5
+ end
data/lib/bulmacomp.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bulmacomp/version'
4
+ require 'bulmacomp/engine'
5
+ require 'view_component'
6
+
7
+ # Bulmacomp module, contain all gem components
8
+ module Bulmacomp
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :bulmacomp do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulmacomp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - MDreW
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-21 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.0.4.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.4.2
27
+ description: Collection of view components for bulma css framework
28
+ email:
29
+ - andrea.ranaldi@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/components/bulmacomp/breadcrumb_component.rb
38
+ - app/components/bulmacomp/card_component.rb
39
+ - app/components/bulmacomp/menu_component.rb
40
+ - app/components/bulmacomp/modal_component.rb
41
+ - app/components/bulmacomp/navbar_component.rb
42
+ - app/components/bulmacomp/panel_component.rb
43
+ - lib/bulmacomp.rb
44
+ - lib/bulmacomp/engine.rb
45
+ - lib/bulmacomp/version.rb
46
+ - lib/tasks/bulmacomp_tasks.rake
47
+ homepage: https://github.com/isprambiente/bulmacomp
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/isprambiente/bulmacomp
52
+ source_code_uri: https://github.com/MdreW/bulmacomp
53
+ changelog_uri: https://github.com/MdreW/bulmacomp
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.4.8
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Rails 'View Components' for Bulma
73
+ test_files: []