element_component 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: de4f0a64912afadf91c8b8abe4e9a59e02a3f1d3635e1fada9b7dab402af582a
4
+ data.tar.gz: 558200b3523fafcf340c6826b8686e49daee2933bb6185c2fa23f5e358bc1bd4
5
+ SHA512:
6
+ metadata.gz: ecdecdf70440d27aa7dfd99c211178d1d41d684576ca5d9e20501862a405daa23de78022cf5463eb83443e4fee5332682fe35865246236c0fa14fdeae218c8ae
7
+ data.tar.gz: 84e453f91412f03a78409a59b6076d5b2c3e5620b9c3be509d354bcd82009b33fcccddf5d4b0eb9c610292914871b1151208495f263833b0ad9867793c36d899
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --require spec_helper
3
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in element_component.gemspec
6
+ gemspec
7
+
8
+ gem 'debug'
9
+ gem 'rake', '~> 13.0'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop'
12
+ gem 'simplecov', require: false, group: :test
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ element_component (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ debug (1.5.0)
11
+ irb (>= 1.3.6)
12
+ reline (>= 0.2.7)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
+ io-console (0.5.11)
16
+ irb (1.4.1)
17
+ reline (>= 0.3.0)
18
+ parallel (1.22.1)
19
+ parser (3.1.2.0)
20
+ ast (~> 2.4.1)
21
+ rainbow (3.1.1)
22
+ rake (13.0.6)
23
+ regexp_parser (2.3.1)
24
+ reline (0.3.1)
25
+ io-console (~> 0.5)
26
+ rexml (3.2.5)
27
+ rspec (3.11.0)
28
+ rspec-core (~> 3.11.0)
29
+ rspec-expectations (~> 3.11.0)
30
+ rspec-mocks (~> 3.11.0)
31
+ rspec-core (3.11.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-expectations (3.11.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-mocks (3.11.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-support (3.11.0)
40
+ rubocop (1.28.2)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.1.0.0)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 1.8, < 3.0)
45
+ rexml
46
+ rubocop-ast (>= 1.17.0, < 2.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 1.4.0, < 3.0)
49
+ rubocop-ast (1.17.0)
50
+ parser (>= 3.1.1.0)
51
+ ruby-progressbar (1.11.0)
52
+ simplecov (0.21.2)
53
+ docile (~> 1.1)
54
+ simplecov-html (~> 0.11)
55
+ simplecov_json_formatter (~> 0.1)
56
+ simplecov-html (0.12.3)
57
+ simplecov_json_formatter (0.1.4)
58
+ unicode-display_width (2.1.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+ x86_64-linux
63
+
64
+ DEPENDENCIES
65
+ debug
66
+ element_component!
67
+ rake (~> 13.0)
68
+ rspec (~> 3.0)
69
+ rubocop
70
+ simplecov
71
+
72
+ BUNDLED WITH
73
+ 2.1.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ElementComponent
2
+
3
+ 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/element_component`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'element_component'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install element_component
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/element_component.
36
+
37
+ ## License
38
+
39
+ 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
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'element_component'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulma
4
+ class Datagrid < El::Element
5
+ def initialize()
6
+ super('div')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulma
4
+ class Menu < El::Aside
5
+ def initialize
6
+ super()
7
+
8
+ menu_label = El::Element.new('p')
9
+ menu_label.add_content 'General'
10
+
11
+ menu_list = El::Ul.new
12
+ menu_item = menu_list.add_content El::Li.new
13
+ menu_link = El::A.new contents: ['Dashboard']
14
+ menu_item.add_content menu_link
15
+
16
+ add_content menu_label.build
17
+ add_content menu_list.build
18
+
19
+ menu_label.add_content 'Administration', reset: true
20
+ add_content menu_label.build
21
+
22
+ menu_link.add_content 'Team Settings', reset: true
23
+ add_content menu_list.build
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bulma
4
+ class Pagination < El::Nav
5
+ attr_reader :url, :current_page, :first_page, :last_page
6
+
7
+ def initialize(url:, current_page:, first_page: 1, last_page:)
8
+ super()
9
+
10
+ @url, @current_page, @first_page, @last_page = url, current_page, first_page, last_page
11
+
12
+ add_attribute :class, 'pagination'
13
+ add_attribute :role, 'navigation'
14
+ add_attribute 'aria_label', 'pagination'
15
+
16
+ add_content previous_link
17
+ add_content next_link
18
+
19
+ # adds first link to list
20
+ li = list.add_content El::Li.new
21
+ li.add_content make_link(first_page)
22
+
23
+ # adds separator
24
+ list.add_content El::Li.new(contents: [separator])
25
+
26
+ # adds the center links
27
+ if current_page > first_page
28
+ li = list.add_content El::Li.new
29
+ li.add_content make_link(current_page - 1)
30
+ end
31
+
32
+ li = list.add_content El::Li.new
33
+ li.add_content make_link(current_page)
34
+
35
+ if current_page < last_page
36
+ li = list.add_content El::Li.new
37
+ li.add_content make_link(current_page + 1)
38
+ end
39
+
40
+ # adds separator
41
+ list.add_content El::Li.new(contents: [separator])
42
+
43
+ # adds last link to list
44
+ li = El::Li.new
45
+ li.add_content make_link(last_page)
46
+ list.add_content li.build
47
+
48
+ add_content list
49
+ end
50
+
51
+ private
52
+
53
+ def make_link(page_number)
54
+ link = El::A.new
55
+
56
+ link.add_attribute 'arial-label', "Go to page #{page_number}"
57
+ link.add_attribute :href, "#{url}?page=#{page_number}"
58
+ link.add_attribute :class, 'pagination-link'
59
+ link.add_attribute :class, 'is-current' if page_number == current_page
60
+ link.add_content page_number
61
+
62
+ link
63
+ end
64
+
65
+ def list
66
+ @list ||= El::Ul.new attributes: { class: 'pagination-list' }
67
+ end
68
+
69
+ def separator
70
+ @separator ||= El::Span.new attributes: { class: 'pagination-ellipsis' }, contents: ['&hellip;']
71
+ end
72
+
73
+ def previous_link
74
+ link = El::A.new
75
+ link.add_attribute :class, 'pagination-previous'
76
+ link.add_content 'Previous'
77
+
78
+ if current_page > first_page
79
+ link.add_attribute :href, "#{url}?page=#{current_page - 1}"
80
+ else
81
+ link.add_attribute :class, 'is-disabled'
82
+ end
83
+
84
+ link
85
+ end
86
+
87
+ def next_link
88
+ link = El::A.new
89
+ link.add_attribute :class, 'pagination-next'
90
+ link.add_content 'Next'
91
+
92
+ if current_page < last_page
93
+ link.add_attribute :href, "#{url}?page=#{current_page + 1}"
94
+ else
95
+ link.add_attribute :class, 'is-disabled'
96
+ end
97
+
98
+ link
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the link tag
5
+ class A < Element
6
+ def initialize(**options)
7
+ super('a', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the article tag
5
+ class Article < Element
6
+ def initialize
7
+ super('article', closing_tag: true)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the aside tag
5
+ class Aside < Element
6
+ def initialize(**options)
7
+ super('aside', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the element base
5
+ class Element
6
+ attr_reader :element, :attributes, :components
7
+
8
+ def initialize(element, contents: [], attributes: {}, closing_tag: true)
9
+ @element = element
10
+ @closing_tag = closing_tag
11
+
12
+ reset_attributes!
13
+ reset_contents!
14
+ reset_components!
15
+
16
+ contents.each do |content|
17
+ add_content content
18
+ end
19
+
20
+ attributes.each_key do |attribute_key|
21
+ add_attribute attribute_key, attributes[attribute_key]
22
+ end
23
+ end
24
+
25
+ def add_content(content, reset: false)
26
+ reset_contents! if reset
27
+ @contents.push(content)
28
+
29
+ content
30
+ end
31
+
32
+ def add_component(identifier, component)
33
+ identifier = identifier.to_sym
34
+ @components.store identifier, component
35
+ end
36
+
37
+ def get_component(identifier)
38
+ identifier = identifier.to_sym
39
+ @components.fetch identifier
40
+ end
41
+
42
+ def add_attribute(attribute, value, reset: false)
43
+ attribute = attribute.to_sym
44
+
45
+ @attributes.delete attribute if reset
46
+
47
+ return @attributes[attribute].push(value) if @attributes.key?(attribute)
48
+
49
+ @attributes[attribute] = [value]
50
+ end
51
+
52
+ def remove_attribute!(attribute)
53
+ attribute = attribute.to_sym
54
+ @attributes = @attributes.except(attribute)
55
+ end
56
+
57
+ def remove_attribute_value(attribute, value)
58
+ attribute = attribute.to_sym
59
+ attributes[attribute].delete(value)
60
+ end
61
+
62
+ def reset_contents!
63
+ @contents = []
64
+ end
65
+
66
+ def reset_attributes!
67
+ @attributes = {}
68
+ end
69
+
70
+ def reset_components!
71
+ @components = {}
72
+ end
73
+
74
+ def build
75
+ partial = open_tag
76
+
77
+ @contents.each do |content|
78
+ partial << (content.is_a?(Element) ? content.build : content.to_s)
79
+ end
80
+
81
+ partial << close_tag if @closing_tag
82
+ partial
83
+ end
84
+
85
+ private
86
+
87
+ def open_tag
88
+ partial = "<#{@element}"
89
+ @attributes.to_a.inject(partial) do |acc, attr|
90
+ acc << " #{attr[0].to_sym}=\"#{attr[1].join(' ')}\""
91
+ end
92
+
93
+ partial << '>'
94
+ end
95
+
96
+ def close_tag
97
+ "</#{@element}>"
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the form tag
5
+ class Form < Element
6
+ def initialize(method: 'POST', action: '/')
7
+ super('form', closing_tag: true)
8
+
9
+ add_attribute(:method, method)
10
+ add_attribute(:action, action)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the input tag
5
+ class Input < Element
6
+ def initialize(type: 'text')
7
+ super('input', closing_tag: false)
8
+
9
+ add_attribute(:type, type)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the li tag
5
+ class Li < Element
6
+ def initialize(**options)
7
+ super('li', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the nav tag
5
+ class Nav < Element
6
+ def initialize(**options)
7
+ super('nav', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the span tag
5
+ class Span < Element
6
+ def initialize(**options)
7
+ super('span', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the table tag
5
+ class Table < Element
6
+ def initialize
7
+ super('table', closing_tag: true)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the tbody tag
5
+ class Tbody < Element
6
+ def initialize(**options)
7
+ super('tbody', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the td tag
5
+ class Td < Element
6
+ def initialize
7
+ super('td', closing_tag: true)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the Tfoot tag
5
+ class Tfoot < Element
6
+ def initialize(**options)
7
+ super('tfoot', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the th tag
5
+ class Th < Element
6
+ def initialize
7
+ super('th', closing_tag: true)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the Thead tag
5
+ class Thead < Element
6
+ def initialize(**options)
7
+ super('thead', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the tr tag
5
+ class Tr < Element
6
+ def initialize
7
+ super('tr', closing_tag: true)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module El
4
+ # represent the ul tag
5
+ class Ul < Element
6
+ def initialize(**options)
7
+ super('ul', **options)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElementComponent
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Core elements
4
+ require_relative 'element_component/version'
5
+ require_relative 'element_component/core/element'
6
+ require_relative 'element_component/core/input'
7
+ require_relative 'element_component/core/form'
8
+ require_relative 'element_component/core/nav'
9
+ require_relative 'element_component/core/a'
10
+ require_relative 'element_component/core/article'
11
+ require_relative 'element_component/core/li'
12
+ require_relative 'element_component/core/ul'
13
+ require_relative 'element_component/core/span'
14
+ require_relative 'element_component/core/table'
15
+ require_relative 'element_component/core/tr'
16
+ require_relative 'element_component/core/th'
17
+ require_relative 'element_component/core/td'
18
+ require_relative 'element_component/core/aside'
19
+
20
+ # Bulma components
21
+ require_relative 'element_component/bulma/pagination'
22
+ require_relative 'element_component/bulma/menu'
23
+
24
+ # Tailwind components
25
+
26
+ module El
27
+ class Error < StandardError; end
28
+ end
29
+
30
+ module Bulma
31
+ class Error < StandardError; end
32
+
33
+ CDN = 'https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css'
34
+ end
35
+
36
+ module Tailwind
37
+ class Error < StandardError; end
38
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: element_component
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - João Paulo Correia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - joaopaulocorreia1010@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - lib/element_component.rb
29
+ - lib/element_component/bulma/datagrid.rb
30
+ - lib/element_component/bulma/menu.rb
31
+ - lib/element_component/bulma/pagination.rb
32
+ - lib/element_component/core/a.rb
33
+ - lib/element_component/core/article.rb
34
+ - lib/element_component/core/aside.rb
35
+ - lib/element_component/core/element.rb
36
+ - lib/element_component/core/form.rb
37
+ - lib/element_component/core/input.rb
38
+ - lib/element_component/core/li.rb
39
+ - lib/element_component/core/nav.rb
40
+ - lib/element_component/core/span.rb
41
+ - lib/element_component/core/table.rb
42
+ - lib/element_component/core/tbody.rb
43
+ - lib/element_component/core/td.rb
44
+ - lib/element_component/core/tfoot.rb
45
+ - lib/element_component/core/th.rb
46
+ - lib/element_component/core/thead.rb
47
+ - lib/element_component/core/tr.rb
48
+ - lib/element_component/core/ul.rb
49
+ - lib/element_component/version.rb
50
+ homepage:
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
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: 2.6.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.3.7
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Element Component
73
+ test_files: []