locastyle_components 0.1.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bde2e4bedfbf430945bb939f5492c6ae283865d5
4
+ data.tar.gz: 24b2c57871e7a9beddefcbc8b747dbaad216b075
5
+ SHA512:
6
+ metadata.gz: 6726d62ebcd307b7889d2215afd6b2c44310622613936d65c979df87655822147467a25ef3b478465362fdcd789ac3acb832a5a1c693bf78ef163864cc63029b
7
+ data.tar.gz: 41b67490fcb85e5165b5e92fc9253b2d4c341fb258de445567e2a4db3bce26aa4219015f2499add1f78aaf6f29967e31e5c8795d76313dadcdd32d66b71b3c5c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,36 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Rails/FindBy:
5
+ Enabled: false
6
+
7
+ Style/Encoding:
8
+ Enabled: false
9
+
10
+ Style/AsciiComments:
11
+ Enabled: false
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/EmptyLinesAroundClassBody:
20
+ Enabled: false
21
+
22
+ Style/EmptyLinesAroundModuleBody:
23
+ Enabled: false
24
+
25
+ Style/ClassAndModuleChildren:
26
+ Enabled: false
27
+
28
+ Metrics/LineLength:
29
+ Max: 160
30
+
31
+ EndOfLine:
32
+ Enabled: false
33
+
34
+ Metrics/MethodLength:
35
+ CountComments: false # count full line comments?
36
+ Max: 12
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in locastyle_components.gemspec
6
+ gemspec
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ locastyle_components (0.1.0)
5
+ actionview
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionview (5.1.4)
11
+ activesupport (= 5.1.4)
12
+ builder (~> 3.1)
13
+ erubi (~> 1.4)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
16
+ activesupport (5.1.4)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ builder (3.2.3)
22
+ coderay (1.1.2)
23
+ concurrent-ruby (1.0.5)
24
+ crass (1.0.3)
25
+ diff-lcs (1.3)
26
+ erubi (1.7.0)
27
+ i18n (0.9.1)
28
+ concurrent-ruby (~> 1.0)
29
+ loofah (2.1.1)
30
+ crass (~> 1.0.2)
31
+ nokogiri (>= 1.5.9)
32
+ method_source (0.9.0)
33
+ mini_portile2 (2.3.0)
34
+ minitest (5.10.3)
35
+ nokogiri (1.8.1)
36
+ mini_portile2 (~> 2.3.0)
37
+ pry (0.11.3)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.9.0)
40
+ pry-remote (0.1.8)
41
+ pry (~> 0.9)
42
+ slop (~> 3.0)
43
+ rails-dom-testing (2.0.3)
44
+ activesupport (>= 4.2.0)
45
+ nokogiri (>= 1.6)
46
+ rails-html-sanitizer (1.0.3)
47
+ loofah (~> 2.0)
48
+ rake (10.5.0)
49
+ rspec (3.7.0)
50
+ rspec-core (~> 3.7.0)
51
+ rspec-expectations (~> 3.7.0)
52
+ rspec-mocks (~> 3.7.0)
53
+ rspec-core (3.7.0)
54
+ rspec-support (~> 3.7.0)
55
+ rspec-expectations (3.7.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.7.0)
58
+ rspec-mocks (3.7.0)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.7.0)
61
+ rspec-support (3.7.0)
62
+ slop (3.6.0)
63
+ thread_safe (0.3.6)
64
+ tzinfo (1.2.4)
65
+ thread_safe (~> 0.1)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler (~> 1.16)
72
+ locastyle_components!
73
+ pry
74
+ pry-remote
75
+ rake (~> 10.0)
76
+ rspec (~> 3.0)
77
+
78
+ BUNDLED WITH
79
+ 1.16.0
@@ -0,0 +1,109 @@
1
+ # LocastyleComponents
2
+
3
+ Gem contendo helpers para construção de componentes do locastyle em templates ERB.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'locastyle_components'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Componentes Disponíveis
18
+
19
+ Por ser uma versão inicial, essa gem contempla somente alguns componentes, podendo não atender alguns casos específicos.
20
+
21
+ ### Componentes de Formulário
22
+
23
+ - Botão Switch [Ver original](http://opensource.locaweb.com.br/locawebstyle/documentacao/componentes/botao-switch/)
24
+
25
+ ### Componentes Comuns
26
+
27
+ - Collapse [Ver original](http://opensource.locaweb.com.br/locawebstyle/documentacao/componentes/collapse/)
28
+
29
+
30
+ ## Usage
31
+
32
+ ### Componentes de Formulário
33
+
34
+ Para usar os componentes de formulário é necessário que sejam chamados dentro de um bloco form do rails (`form_for`):
35
+
36
+ ```
37
+ <%= form_for(:user) do |f| %>
38
+ <%= f.gem_component_here(options) %>
39
+ <% end %>
40
+ ```
41
+
42
+ #### Botão Switch
43
+
44
+ Parâmetros:
45
+ - Atributo a ser controlad
46
+ - Hash de argumentos (:label)
47
+
48
+
49
+ ```
50
+ # Usando nome do atributo como label
51
+ <%= f.locastyle_switch_button(:status) %>
52
+
53
+ # Usando uma label customizada
54
+ <%= f.locastyle_switch_button(:status, label: 'Custom') %>
55
+
56
+ # Sem label
57
+ <%= f.locastyle_switch_button(:default, label: false) %>
58
+ ```
59
+
60
+ ### Componentes Comuns
61
+
62
+ Esses componentes podem ser chamados em qualquer ponto da view.
63
+
64
+ #### Collapse
65
+
66
+ Parâmetros:
67
+ - Hash de argumentos (:title)
68
+ - Bloco com o conteúdo
69
+
70
+ Recebe um Hash como parâmetro e no momento utiliza somente a chave `:title`. O conteúdo deve ser passado em um bloco.
71
+
72
+ ```
73
+ <% content_for :collapse_header do %>
74
+ <h1 class="ls-collapse-title">Title</h1>
75
+ <p>Subtitle</p>
76
+ <% end %>
77
+
78
+ <%= locastyle_collapse_tag({ title: yield(:collapse_header) }) do %>
79
+ <p>Content</p>
80
+ <% end %>
81
+ ```
82
+
83
+ ```
84
+ <%= locastyle_collapse_tag({ title: some_helper }) do %>
85
+ <p>Content</p>
86
+ <% end %>
87
+ ```
88
+
89
+ ```
90
+ <%= locastyle_collapse_tag(some_helper) do %>
91
+ content_helper
92
+ <% end %>
93
+ ```
94
+
95
+ ```
96
+ <%= locastyle_collapse_tag(some_helper) do %>
97
+ <p>Content</p>
98
+ <% end %>
99
+ ```
100
+
101
+ ```
102
+ <%= locastyle_collapse_tag({ title: I18n.t('key') }) do %>
103
+ <p>Content</p>
104
+ <% end %>
105
+ ```
106
+
107
+ ## Development
108
+
109
+ Ao realizar alguma alteração, lembre-se de manter o que já tinha funcionando. Escreva casos de testes sempre que possível.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "locastyle_components"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,14 @@
1
+ require 'action_view/base'
2
+ require 'action_view/helpers/form_helper'
3
+
4
+ module ActionView
5
+ class Base
6
+ include LocastyleComponents::Tags
7
+ end
8
+
9
+ module Helpers
10
+ class FormBuilder
11
+ include LocastyleComponents::Forms
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ require 'locastyle_components/version'
2
+ require 'locastyle_components/forms'
3
+ require 'locastyle_components/tags'
4
+ require 'action_view_patch'
5
+
6
+ module LocastyleComponents; end
@@ -0,0 +1,10 @@
1
+ require 'locastyle_components/forms/base'
2
+ require 'locastyle_components/forms/switch_button'
3
+
4
+ module LocastyleComponents
5
+ module Forms
6
+ def locastyle_switch_button(attribute, options = {})
7
+ LocastyleComponents::Forms::SwitchButton.new(self, @template, attribute, options).build
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module LocastyleComponents
2
+ module Forms
3
+
4
+ #
5
+ # Classe contendo metodos em comum entre os componentes
6
+ #
7
+ class Base
8
+ def i18n_attr(param)
9
+ return param unless i18n?
10
+ I18n.t(param, scope: 'activerecord.attributes')
11
+ end
12
+
13
+ def i18n?
14
+ Object.const_defined?('I18n')
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,65 @@
1
+ module LocastyleComponents
2
+ module Forms
3
+
4
+ #
5
+ # http://opensource.locaweb.com.br/locawebstyle/documentacao/componentes/botao-switch/
6
+ #
7
+ class SwitchButton < Base
8
+ attr_accessor :form, :view, :object, :attribute, :klass, :options
9
+
10
+ def initialize(form, view, attribute, options)
11
+ @form = form
12
+ @view = view
13
+ @attribute = attribute.to_s
14
+ @options = Hash(options)
15
+
16
+ @object = form.object
17
+ @klass = object.class.name.underscore
18
+ end
19
+
20
+ def build
21
+ return label + switch if use_label?
22
+ switch
23
+ end
24
+
25
+ private
26
+
27
+ def use_label?
28
+ options[:label] != false
29
+ end
30
+
31
+ def label
32
+ text = options[:label] || i18n_attr(klass + '.' + attribute)
33
+
34
+ view.label_tag(html_attr, text)
35
+ end
36
+
37
+ def switch
38
+ args = { class: 'ls-switch-btn', data: { 'ls-module' => 'switchButton' } }
39
+
40
+ view.content_tag(:div, args) do
41
+ hidden + input + toggle
42
+ end
43
+ end
44
+
45
+ def hidden
46
+ view.hidden_field_tag(html_attr, false)
47
+ end
48
+
49
+ def input
50
+ view.check_box_tag(html_attr, 1, object.send(attribute))
51
+ end
52
+
53
+ def toggle
54
+ view.label_tag(html_attr, class: 'ls-switch-label') do
55
+ view.content_tag :span
56
+ end
57
+ end
58
+
59
+ def html_attr
60
+ form.object_name
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ require 'locastyle_components/tags/base'
2
+ require 'locastyle_components/tags/collapse'
3
+
4
+ module LocastyleComponents
5
+ module Tags
6
+ def locastyle_collapse_tag(options = {}, &block)
7
+ LocastyleComponents::Tags::Collapse.new(self, block, options).build
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module LocastyleComponents
2
+ module Tags
3
+ class Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,45 @@
1
+ module LocastyleComponents
2
+ module Tags
3
+
4
+ #
5
+ # http://opensource.locaweb.com.br/locawebstyle/documentacao/componentes/collapse/
6
+ #
7
+ class Collapse < Base
8
+ attr_accessor :view, :options, :id, :block
9
+
10
+ def initialize(view, block, options)
11
+ @view = view
12
+ @options = Hash(options)
13
+ @id = Time.now.to_f.to_s.gsub(/\D/, '')
14
+ @block = block
15
+ end
16
+
17
+ def build
18
+ base do
19
+ header + body
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def base(&_block)
26
+ args = { class: 'ls-collapse', data: { 'ls-module' => 'collapse', 'target' => '#' + id } }
27
+
28
+ view.content_tag :div, args do
29
+ yield
30
+ end
31
+ end
32
+
33
+ def header
34
+ view.link_to options[:title], '#', class: 'ls-collapse-header'
35
+ end
36
+
37
+ def body
38
+ view.content_tag :div, class: 'ls-collapse-body', id: id do
39
+ view.raw block.call
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module LocastyleComponents
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'locastyle_components/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'locastyle_components'
8
+ spec.version = LocastyleComponents::VERSION
9
+ spec.authors = ['Felipe Ruoso']
10
+ spec.email = ['fruoso@tray.net.br']
11
+
12
+ spec.summary = 'Wrapper gem to build locastyle components'
13
+ spec.description = 'This gem aims to improve development by calling'
14
+ spec.homepage = ""
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'actionview'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.16'
35
+ spec.add_development_dependency 'pry'
36
+ spec.add_development_dependency 'pry-remote'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locastyle_components
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Felipe Ruoso
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-remote
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: This gem aims to improve development by calling
98
+ email:
99
+ - fruoso@tray.net.br
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/action_view_patch.rb
115
+ - lib/locastyle_components.rb
116
+ - lib/locastyle_components/forms.rb
117
+ - lib/locastyle_components/forms/base.rb
118
+ - lib/locastyle_components/forms/switch_button.rb
119
+ - lib/locastyle_components/tags.rb
120
+ - lib/locastyle_components/tags/base.rb
121
+ - lib/locastyle_components/tags/collapse.rb
122
+ - lib/locastyle_components/version.rb
123
+ - locastyle_components.gemspec
124
+ homepage: ''
125
+ licenses: []
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.6.11
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Wrapper gem to build locastyle components
148
+ test_files: []