element_component 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de4f0a64912afadf91c8b8abe4e9a59e02a3f1d3635e1fada9b7dab402af582a
4
- data.tar.gz: 558200b3523fafcf340c6826b8686e49daee2933bb6185c2fa23f5e358bc1bd4
3
+ metadata.gz: d0f12674a760bdf815e6ae25fccbadb96032dacc122eca06c9ad7335b91fe226
4
+ data.tar.gz: d912a66d464b5f0ead36c41faa7e20d12b5bbd56871f3112b922e11a9bc83aa9
5
5
  SHA512:
6
- metadata.gz: ecdecdf70440d27aa7dfd99c211178d1d41d684576ca5d9e20501862a405daa23de78022cf5463eb83443e4fee5332682fe35865246236c0fa14fdeae218c8ae
7
- data.tar.gz: 84e453f91412f03a78409a59b6076d5b2c3e5620b9c3be509d354bcd82009b33fcccddf5d4b0eb9c610292914871b1151208495f263833b0ad9867793c36d899
6
+ metadata.gz: 25affca2d6a9f235d515060f943ebff6901fc2590f89a0b9782f4c43ce9f3d143cbcb8a2be976db48478328fbcdc903ba401bbeaa98901564f8f8f5f05f249a5
7
+ data.tar.gz: 19e19dccf1862858c47520a4afa3f0bf8aa364461dda3f30243c1d0400a49cdbb8a283c7aba3975a6cbb439d2f8aa7cf8cea5691663183cdc23c4237afbc5dc4
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ # Mude para a versão de Ruby a ser utilizada e inclua aqui outros arquivos que
2
+ # você considera importante que o RuboCop não execute como: node_modules, etc..
3
+ AllCops:
4
+ TargetRubyVersion: 3.1.2
5
+ Exclude:
6
+ - 'bin/**/*'
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ Style/FrozenStringLiteralComment:
12
+ Enabled: false
13
+
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+ Metrics/AbcSize:
17
+ Enabled: false
18
+
19
+ Metrics/BlockLength:
20
+ ExcludedMethods: ['describe', 'context', 'feature', 'scenario', 'let']
data/Gemfile CHANGED
@@ -9,4 +9,3 @@ gem 'debug'
9
9
  gem 'rake', '~> 13.0'
10
10
  gem 'rspec', '~> 3.0'
11
11
  gem 'rubocop'
12
- gem 'simplecov', require: false, group: :test
data/Gemfile.lock CHANGED
@@ -11,7 +11,6 @@ GEM
11
11
  irb (>= 1.3.6)
12
12
  reline (>= 0.2.7)
13
13
  diff-lcs (1.5.0)
14
- docile (1.4.0)
15
14
  io-console (0.5.11)
16
15
  irb (1.4.1)
17
16
  reline (>= 0.3.0)
@@ -49,12 +48,6 @@ GEM
49
48
  rubocop-ast (1.17.0)
50
49
  parser (>= 3.1.1.0)
51
50
  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
51
  unicode-display_width (2.1.0)
59
52
 
60
53
  PLATFORMS
@@ -67,7 +60,6 @@ DEPENDENCIES
67
60
  rake (~> 13.0)
68
61
  rspec (~> 3.0)
69
62
  rubocop
70
- simplecov
71
63
 
72
64
  BUNDLED WITH
73
65
  2.1.2
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # ElementComponent
2
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
3
+ Build html
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,18 +20,17 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
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
23
+ ```
24
+ maker = El::Maker.new
25
+ form = maker.form(attribute: { class: 'has-background-color', method: 'GET', action: '/', turbo: false }) do |form|
26
+ input = maker.input(attribute: { type: 'text', name: 'email', value: nil })
27
+ form.add_content input
34
28
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/element_component.
29
+ button = maker.button(content: 'Save', attribute: { type: 'submit'})
30
+ div = maker.div(content: button, attribute: { class: 'buttons' })
36
31
 
37
- ## License
32
+ form.add_content div
33
+ end
38
34
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
35
+ puts form.build
36
+ ```
@@ -3,23 +3,23 @@
3
3
  module El
4
4
  # represent the element base
5
5
  class Element
6
- attr_reader :element, :attributes, :components
6
+ attr_reader :element, :attributes, :contents
7
7
 
8
- def initialize(element, contents: [], attributes: {}, closing_tag: true)
8
+ def initialize(element, content: [], attribute: {}, closing_tag: true)
9
9
  @element = element
10
10
  @closing_tag = closing_tag
11
+ @objects = []
11
12
 
12
13
  reset_attributes!
13
14
  reset_contents!
14
- reset_components!
15
15
 
16
- contents.each do |content|
16
+ if content.is_a? Array
17
+ content.each { |item| add_content item }
18
+ else
17
19
  add_content content
18
20
  end
19
21
 
20
- attributes.each_key do |attribute_key|
21
- add_attribute attribute_key, attributes[attribute_key]
22
- end
22
+ attribute.each_key { |key| add_attribute key, attribute[key] }
23
23
  end
24
24
 
25
25
  def add_content(content, reset: false)
@@ -29,16 +29,6 @@ module El
29
29
  content
30
30
  end
31
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
32
  def add_attribute(attribute, value, reset: false)
43
33
  attribute = attribute.to_sym
44
34
 
@@ -67,34 +57,23 @@ module El
67
57
  @attributes = {}
68
58
  end
69
59
 
70
- def reset_components!
71
- @components = {}
72
- end
73
-
74
60
  def build
75
- partial = open_tag
61
+ html = "<#{@element}"
62
+ html << (mount_attributes.empty? ? '>' : " #{mount_attributes}>")
76
63
 
77
- @contents.each do |content|
78
- partial << (content.is_a?(Element) ? content.build : content.to_s)
79
- end
64
+ html << mount_content
80
65
 
81
- partial << close_tag if @closing_tag
82
- partial
66
+ html << "</#{@element}>" if @closing_tag
83
67
  end
84
68
 
85
69
  private
86
70
 
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 << '>'
71
+ def mount_attributes
72
+ @attributes.map { |attr| "#{attr[0].to_sym}=\"#{attr[1].join(' ')}\"" }.join(' ')
94
73
  end
95
74
 
96
- def close_tag
97
- "</#{@element}>"
75
+ def mount_content
76
+ @contents.map { |content| content.is_a?(Element) ? content.build : content.to_s }.join
98
77
  end
99
78
  end
100
79
  end
@@ -0,0 +1,9 @@
1
+ module El
2
+ class Maker
3
+ def method_missing(method, **args, &block)
4
+ new_element = El::Element.new(method.to_s.gsub('_', '-'), **args)
5
+ block.call new_element if block_given?
6
+ new_element
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElementComponent
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -3,36 +3,8 @@
3
3
  # Core elements
4
4
  require_relative 'element_component/version'
5
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
6
+ require_relative 'element_component/core/maker'
25
7
 
26
8
  module El
27
9
  class Error < StandardError; end
28
10
  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 CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: element_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Paulo Correia
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - joaopaulocorreia1010@gmail.com
16
16
  executables: []
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".rspec"
21
+ - ".rubocop.yml"
21
22
  - Gemfile
22
23
  - Gemfile.lock
23
24
  - LICENSE.txt
@@ -26,32 +27,14 @@ files:
26
27
  - bin/console
27
28
  - bin/setup
28
29
  - 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
30
  - 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
31
+ - lib/element_component/core/maker.rb
49
32
  - lib/element_component/version.rb
50
- homepage:
33
+ homepage:
51
34
  licenses:
52
35
  - MIT
53
36
  metadata: {}
54
- post_install_message:
37
+ post_install_message:
55
38
  rdoc_options: []
56
39
  require_paths:
57
40
  - lib
@@ -66,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
49
  - !ruby/object:Gem::Version
67
50
  version: '0'
68
51
  requirements: []
69
- rubygems_version: 3.3.7
70
- signing_key:
52
+ rubygems_version: 3.4.10
53
+ signing_key:
71
54
  specification_version: 4
72
55
  summary: Element Component
73
56
  test_files: []
@@ -1,9 +0,0 @@
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
@@ -1,26 +0,0 @@
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
@@ -1,101 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,12 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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