element_component 0.2.0 → 0.4.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: d0f12674a760bdf815e6ae25fccbadb96032dacc122eca06c9ad7335b91fe226
4
- data.tar.gz: d912a66d464b5f0ead36c41faa7e20d12b5bbd56871f3112b922e11a9bc83aa9
3
+ metadata.gz: fb69cb724b6274a5f95967fbabef32f6e1f5fb9bbf2428775a3237708cc7d6da
4
+ data.tar.gz: 50b2252d0c9315efc8c660910d0924dc6506552d09cbd1fc2f49e2309174f2ba
5
5
  SHA512:
6
- metadata.gz: 25affca2d6a9f235d515060f943ebff6901fc2590f89a0b9782f4c43ce9f3d143cbcb8a2be976db48478328fbcdc903ba401bbeaa98901564f8f8f5f05f249a5
7
- data.tar.gz: 19e19dccf1862858c47520a4afa3f0bf8aa364461dda3f30243c1d0400a49cdbb8a283c7aba3975a6cbb439d2f8aa7cf8cea5691663183cdc23c4237afbc5dc4
6
+ metadata.gz: 98abc01a0787f60a2998f7f62c611fe51a58eaa8ee629e4bfc885da7ccf6b3a11a9e1f2539d206cfa379222caf5d821206f31558e9f7c47afe1ffa9a3addcaf8
7
+ data.tar.gz: bb664c8ad1a7f627f43f1f44898937efeb9c3fc916fca6a65c0b6ae01e1267326d0cff703e476f3748f41cb589b4c0f7c40f236b4787849efcb2029897b3ce78
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --format documentation
2
- --require spec_helper
3
2
  --color
3
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,20 +1,22 @@
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
1
  AllCops:
4
- TargetRubyVersion: 3.1.2
5
- Exclude:
6
- - 'bin/**/*'
2
+ TargetRubyVersion: 3.1
3
+ SuggestExtensions: false
4
+ NewCops: enable
7
5
 
8
6
  Documentation:
9
7
  Enabled: false
10
8
 
11
- Style/FrozenStringLiteralComment:
12
- Enabled: false
13
-
14
9
  Metrics/MethodLength:
15
10
  Enabled: false
16
- Metrics/AbcSize:
17
- Enabled: false
18
11
 
19
12
  Metrics/BlockLength:
20
- ExcludedMethods: ['describe', 'context', 'feature', 'scenario', 'let']
13
+ Enabled: false
14
+
15
+ Style/MissingRespondToMissing:
16
+ Enabled: false
17
+
18
+ Style/StringLiterals:
19
+ EnforcedStyle: double_quotes
20
+
21
+ Style/StringLiteralsInInterpolation:
22
+ EnforcedStyle: double_quotes
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 TODO: Write your name
3
+ Copyright (c) 2025 João Paulo Correia
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,27 +1,25 @@
1
1
  # ElementComponent
2
2
 
3
- Build html
3
+ HTML builder
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Install the gem and add to the application's Gemfile by executing:
8
8
 
9
- ```ruby
10
- gem 'element_component'
9
+ ```bash
10
+ bundle add element_component
11
11
  ```
12
12
 
13
- And then execute:
14
-
15
- $ bundle install
16
-
17
- Or install it yourself as:
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
14
 
19
- $ gem install element_component
15
+ ```bash
16
+ gem install element_component
17
+ ```
20
18
 
21
19
  ## Usage
22
20
 
23
- ```
24
- maker = El::Maker.new
21
+ ```ruby
22
+ maker = ElementComponent::Core::Maker.new
25
23
  form = maker.form(attribute: { class: 'has-background-color', method: 'GET', action: '/', turbo: false }) do |form|
26
24
  input = maker.input(attribute: { type: 'text', name: 'email', value: nil })
27
25
  form.add_content input
@@ -34,3 +32,28 @@ end
34
32
 
35
33
  puts form.build
36
34
  ```
35
+
36
+ ## Output
37
+
38
+ ```html
39
+ <form class="has-background-color" method="GET" action="/" turbo="false"><input type="text" name="email" value=""></input><div class="buttons"><button type="submit">Save</button></div></form>
40
+ ```
41
+
42
+ ## Development
43
+
44
+ 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.
45
+
46
+ 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).
47
+
48
+ ## TODO
49
+ [ ] - Cache
50
+ [ ] - Bulma components
51
+ [ ] - Bootstrap components
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joaopaulocorreia/element_component.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- task default: :spec
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -1,79 +1,80 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module El
4
- # represent the element base
5
- class Element
6
- attr_reader :element, :attributes, :contents
7
-
8
- def initialize(element, content: [], attribute: {}, closing_tag: true)
9
- @element = element
10
- @closing_tag = closing_tag
11
- @objects = []
12
-
13
- reset_attributes!
14
- reset_contents!
15
-
16
- if content.is_a? Array
17
- content.each { |item| add_content item }
18
- else
19
- add_content content
3
+ module ElementComponent
4
+ module Core
5
+ class Element
6
+ attr_reader :element, :attributes, :contents
7
+
8
+ def initialize(element, content: [], attribute: {}, closing_tag: true)
9
+ @element = element
10
+ @closing_tag = closing_tag
11
+ @objects = []
12
+
13
+ reset_attributes!
14
+ reset_contents!
15
+
16
+ if content.is_a? Array
17
+ content.each { |item| add_content item }
18
+ else
19
+ add_content content
20
+ end
21
+
22
+ attribute.each_key { |key| add_attribute key, attribute[key] }
20
23
  end
21
24
 
22
- attribute.each_key { |key| add_attribute key, attribute[key] }
23
- end
24
-
25
- def add_content(content, reset: false)
26
- reset_contents! if reset
27
- @contents.push(content)
25
+ def add_content(content, reset: false)
26
+ reset_contents! if reset
27
+ @contents.push(content)
28
28
 
29
- content
30
- end
29
+ content
30
+ end
31
31
 
32
- def add_attribute(attribute, value, reset: false)
33
- attribute = attribute.to_sym
32
+ def add_attribute(attribute, value, reset: false)
33
+ attribute = attribute.to_sym
34
34
 
35
- @attributes.delete attribute if reset
35
+ @attributes.delete attribute if reset
36
36
 
37
- return @attributes[attribute].push(value) if @attributes.key?(attribute)
37
+ return @attributes[attribute].push(value) if @attributes.key?(attribute)
38
38
 
39
- @attributes[attribute] = [value]
40
- end
39
+ @attributes[attribute] = [value]
40
+ end
41
41
 
42
- def remove_attribute!(attribute)
43
- attribute = attribute.to_sym
44
- @attributes = @attributes.except(attribute)
45
- end
42
+ def remove_attribute!(attribute)
43
+ attribute = attribute.to_sym
44
+ @attributes = @attributes.except(attribute)
45
+ end
46
46
 
47
- def remove_attribute_value(attribute, value)
48
- attribute = attribute.to_sym
49
- attributes[attribute].delete(value)
50
- end
47
+ def remove_attribute_value(attribute, value)
48
+ attribute = attribute.to_sym
49
+ attributes[attribute].delete(value)
50
+ end
51
51
 
52
- def reset_contents!
53
- @contents = []
54
- end
52
+ def reset_contents!
53
+ @contents = []
54
+ end
55
55
 
56
- def reset_attributes!
57
- @attributes = {}
58
- end
56
+ def reset_attributes!
57
+ @attributes = {}
58
+ end
59
59
 
60
- def build
61
- html = "<#{@element}"
62
- html << (mount_attributes.empty? ? '>' : " #{mount_attributes}>")
60
+ def build
61
+ html = "<#{@element}"
62
+ html << (mount_attributes.empty? ? ">" : " #{mount_attributes}>")
63
63
 
64
- html << mount_content
64
+ html << mount_content
65
65
 
66
- html << "</#{@element}>" if @closing_tag
67
- end
66
+ html << "</#{@element}>" if @closing_tag
67
+ end
68
68
 
69
- private
69
+ private
70
70
 
71
- def mount_attributes
72
- @attributes.map { |attr| "#{attr[0].to_sym}=\"#{attr[1].join(' ')}\"" }.join(' ')
73
- end
71
+ def mount_attributes
72
+ @attributes.map { |attr| "#{attr[0].to_sym}=\"#{attr[1].join(" ")}\"" }.join(" ")
73
+ end
74
74
 
75
- def mount_content
76
- @contents.map { |content| content.is_a?(Element) ? content.build : content.to_s }.join
75
+ def mount_content
76
+ @contents.map { |content| content.is_a?(Element) ? content.build : content.to_s }.join
77
+ end
77
78
  end
78
79
  end
79
80
  end
@@ -1,9 +1,13 @@
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
1
+ # frozen_string_literal: true
2
+
3
+ module ElementComponent
4
+ module Core
5
+ class Maker
6
+ def method_missing(method, **args, &block)
7
+ new_element = ElementComponent::Core::Element.new(method.to_s.gsub("_", "-"), **args)
8
+ block.call new_element if block_given?
9
+ new_element
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElementComponent
4
- VERSION = '0.2.0'
4
+ VERSION = "0.4.0"
5
5
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Core elements
4
- require_relative 'element_component/version'
5
- require_relative 'element_component/core/element'
6
- require_relative 'element_component/core/maker'
3
+ require_relative "element_component/version"
4
+ require_relative "element_component/core/element"
5
+ require_relative "element_component/core/maker"
7
6
 
8
- module El
7
+ module ElementComponent
9
8
  class Error < StandardError; end
9
+ # Your code goes here...
10
10
  end
@@ -0,0 +1,4 @@
1
+ module ElementComponent
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,40 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: element_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - João Paulo Correia
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-10-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
12
+ description: HTML Builder
14
13
  email:
15
- - joaopaulocorreia1010@gmail.com
14
+ - ijoohn@hotmail.com
16
15
  executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
19
  - ".rspec"
21
20
  - ".rubocop.yml"
22
- - Gemfile
23
- - Gemfile.lock
24
21
  - LICENSE.txt
25
22
  - README.md
26
23
  - Rakefile
27
- - bin/console
28
- - bin/setup
29
24
  - lib/element_component.rb
30
25
  - lib/element_component/core/element.rb
31
26
  - lib/element_component/core/maker.rb
32
27
  - lib/element_component/version.rb
33
- homepage:
28
+ - sig/element_component.rbs
29
+ homepage: https://github.com/joaopaulocorreia/element_component
34
30
  licenses:
35
31
  - MIT
36
- metadata: {}
37
- post_install_message:
32
+ metadata:
33
+ homepage_uri: https://github.com/joaopaulocorreia/element_component
34
+ rubygems_mfa_required: 'true'
38
35
  rdoc_options: []
39
36
  require_paths:
40
37
  - lib
@@ -42,15 +39,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
39
  requirements:
43
40
  - - ">="
44
41
  - !ruby/object:Gem::Version
45
- version: 2.6.0
42
+ version: 3.1.0
46
43
  required_rubygems_version: !ruby/object:Gem::Requirement
47
44
  requirements:
48
45
  - - ">="
49
46
  - !ruby/object:Gem::Version
50
47
  version: '0'
51
48
  requirements: []
52
- rubygems_version: 3.4.10
53
- signing_key:
49
+ rubygems_version: 3.6.9
54
50
  specification_version: 4
55
- summary: Element Component
51
+ summary: HTML Builder
56
52
  test_files: []
data/Gemfile DELETED
@@ -1,11 +0,0 @@
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'
data/Gemfile.lock DELETED
@@ -1,65 +0,0 @@
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
- io-console (0.5.11)
15
- irb (1.4.1)
16
- reline (>= 0.3.0)
17
- parallel (1.22.1)
18
- parser (3.1.2.0)
19
- ast (~> 2.4.1)
20
- rainbow (3.1.1)
21
- rake (13.0.6)
22
- regexp_parser (2.3.1)
23
- reline (0.3.1)
24
- io-console (~> 0.5)
25
- rexml (3.2.5)
26
- rspec (3.11.0)
27
- rspec-core (~> 3.11.0)
28
- rspec-expectations (~> 3.11.0)
29
- rspec-mocks (~> 3.11.0)
30
- rspec-core (3.11.0)
31
- rspec-support (~> 3.11.0)
32
- rspec-expectations (3.11.0)
33
- diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.11.0)
35
- rspec-mocks (3.11.1)
36
- diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.11.0)
38
- rspec-support (3.11.0)
39
- rubocop (1.28.2)
40
- parallel (~> 1.10)
41
- parser (>= 3.1.0.0)
42
- rainbow (>= 2.2.2, < 4.0)
43
- regexp_parser (>= 1.8, < 3.0)
44
- rexml
45
- rubocop-ast (>= 1.17.0, < 2.0)
46
- ruby-progressbar (~> 1.7)
47
- unicode-display_width (>= 1.4.0, < 3.0)
48
- rubocop-ast (1.17.0)
49
- parser (>= 3.1.1.0)
50
- ruby-progressbar (1.11.0)
51
- unicode-display_width (2.1.0)
52
-
53
- PLATFORMS
54
- ruby
55
- x86_64-linux
56
-
57
- DEPENDENCIES
58
- debug
59
- element_component!
60
- rake (~> 13.0)
61
- rspec (~> 3.0)
62
- rubocop
63
-
64
- BUNDLED WITH
65
- 2.1.2
data/bin/console DELETED
@@ -1,15 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
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