alveole 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.gitlab-ci.yml +55 -0
- data/.rubocop.yml +63 -0
- data/.rubocop_todo.yml +12 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +171 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +10 -0
- data/alveole.gemspec +35 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/alveole/components/avatar_component/avatar_component.html.slim +6 -0
- data/lib/alveole/components/avatar_component.rb +9 -0
- data/lib/alveole/components/badge_component/badge_component.html.slim +2 -0
- data/lib/alveole/components/badge_component.rb +8 -0
- data/lib/alveole/components/breadcrumb_component/breadcrumb_component.html.slim +2 -0
- data/lib/alveole/components/breadcrumb_component.rb +8 -0
- data/lib/alveole/components/breadcrumbs_component.rb +7 -0
- data/lib/alveole/components/button_component/button_component.html.slim +5 -0
- data/lib/alveole/components/button_component.rb +15 -0
- data/lib/alveole/components/definition_component/definition_component.html.slim +4 -0
- data/lib/alveole/components/definition_component.rb +13 -0
- data/lib/alveole/components/form_component/form_component.html.slim +3 -0
- data/lib/alveole/components/form_component.rb +3 -0
- data/lib/alveole/components/form_submit_component/form_submit_component.html.slim +1 -0
- data/lib/alveole/components/form_submit_component.rb +7 -0
- data/lib/alveole/components/heading_component/heading_component.html.slim +4 -0
- data/lib/alveole/components/heading_component.rb +8 -0
- data/lib/alveole/components/input_component/input_component.html.slim +17 -0
- data/lib/alveole/components/input_component.rb +42 -0
- data/lib/alveole/components/notice_component/notice_component.html.slim +5 -0
- data/lib/alveole/components/notice_component.rb +15 -0
- data/lib/alveole/components/page_component/page_component.html.slim +10 -0
- data/lib/alveole/components/page_component.rb +4 -0
- data/lib/alveole/components/sidebar_component/sidebar_component.html.slim +7 -0
- data/lib/alveole/components/sidebar_component.rb +4 -0
- data/lib/alveole/components/table_column_component/table_column_component.html.slim +3 -0
- data/lib/alveole/components/table_column_component.rb +12 -0
- data/lib/alveole/components/table_component/table_component.html.slim +7 -0
- data/lib/alveole/components/table_component.rb +3 -0
- data/lib/alveole/components/table_header_component/table_header_component.html.slim +2 -0
- data/lib/alveole/components/table_header_component.rb +8 -0
- data/lib/alveole/components/table_row_component/table_row_component.html.slim +4 -0
- data/lib/alveole/components/table_row_component.rb +3 -0
- data/lib/alveole/components/toolbar_component/toolbar_component.html.slim +7 -0
- data/lib/alveole/components/toolbar_component.rb +4 -0
- data/lib/alveole/concerns/bem.rb +21 -0
- data/lib/alveole/engine.rb +30 -0
- data/lib/alveole/helpers/method_helper.rb +31 -0
- data/lib/alveole/javascript/components.js +5 -0
- data/lib/alveole/previews/avatar_component_preview.rb +11 -0
- data/lib/alveole/previews/badge_component_preview.rb +11 -0
- data/lib/alveole/previews/breadcrumb_component_preview.rb +15 -0
- data/lib/alveole/previews/button_component_preview.rb +7 -0
- data/lib/alveole/previews/definition_component_preview.rb +33 -0
- data/lib/alveole/previews/form_component_preview.rb +18 -0
- data/lib/alveole/previews/form_submit_component_preview.rb +7 -0
- data/lib/alveole/previews/heading_component_preview.rb +11 -0
- data/lib/alveole/previews/input_component_preview.rb +32 -0
- data/lib/alveole/previews/notice_component_preview.rb +15 -0
- data/lib/alveole/previews/page_component_preview.rb +33 -0
- data/lib/alveole/previews/sidebar_component_preview.rb +33 -0
- data/lib/alveole/previews/table_column_component_preview.rb +36 -0
- data/lib/alveole/previews/table_component_preview.rb +12 -0
- data/lib/alveole/previews/table_header_component_preview.rb +27 -0
- data/lib/alveole/previews/table_row_component_preview.rb +18 -0
- data/lib/alveole/previews/toolbar_component_preview.rb +33 -0
- data/lib/alveole/version.rb +3 -0
- data/lib/alveole.rb +16 -0
- data/lib/generators/alveole/config_generator.rb +17 -0
- data/lib/generators/alveole/templates/alveole_config.rb +1 -0
- metadata +197 -0
data/Rakefile
ADDED
data/alveole.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'lib/alveole/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'alveole'
|
5
|
+
spec.version = Alveole::VERSION
|
6
|
+
spec.authors = ['Marine Sourin', 'Marine Domine', 'Cedric Feyaerts', 'Thomas Kienlen']
|
7
|
+
spec.email = ['marinesourin@live.fr', 'marine@captive.fr', 'c.feyaerts@captive.fr', 't.kienlen@captive.fr']
|
8
|
+
|
9
|
+
spec.summary = 'Components and generator for the Alveole design system'
|
10
|
+
spec.homepage = 'https://git.captive.fr' # TODO: fix this
|
11
|
+
spec.license = 'MIT'
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
13
|
+
|
14
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://git.captive.fr' # TODO: fix this
|
18
|
+
spec.metadata['changelog_uri'] = 'https://git.captive.fr' # TODO: fix this
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_dependency 'actionview'
|
30
|
+
spec.add_dependency 'activesupport', '>= 4.1.0'
|
31
|
+
spec.add_dependency 'rails'
|
32
|
+
spec.add_dependency 'view_component', '~> 2.35'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 1.18'
|
35
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'alveole'
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class ButtonComponent < ViewComponent::Base
|
2
|
+
include Alveole::Concerns::Bem
|
3
|
+
|
4
|
+
MODIFIERS = %i[small icon_only primary].freeze
|
5
|
+
|
6
|
+
def initialize(url:, label:, icon: nil, modifiers: [], options: {})
|
7
|
+
super
|
8
|
+
|
9
|
+
@url = url
|
10
|
+
@label = label
|
11
|
+
@icon = icon
|
12
|
+
@options = options
|
13
|
+
self.modifiers = modifiers
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class DefinitionComponent < ViewComponent::Base
|
2
|
+
def initialize(label: nil, value: nil, obj: nil, fieldname: nil, options: {})
|
3
|
+
super
|
4
|
+
|
5
|
+
@obj = obj
|
6
|
+
@fieldname = fieldname
|
7
|
+
@value = value || obj&.send(fieldname)
|
8
|
+
@value = ApplicationController.helpers.format_value(@value, options)
|
9
|
+
@value = '---' if @value.blank?
|
10
|
+
@label = label || ApplicationController.helpers.label_for(obj, fieldname)
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
input[type="submit" name="commit" value=@label class='form__action button button--primary']
|
@@ -0,0 +1,17 @@
|
|
1
|
+
.input class=@bem_classes
|
2
|
+
= @form.label @fieldname, @label, class: 'input__label'
|
3
|
+
- case @type
|
4
|
+
- when :text
|
5
|
+
= @form.text_field @fieldname, @options.merge(class: 'input__input')
|
6
|
+
- when :date
|
7
|
+
= @form.text_field @fieldname, @options.merge(class: 'input__input datepicker')
|
8
|
+
- when :color
|
9
|
+
= @form.color_field @fieldname, @options
|
10
|
+
- when :select
|
11
|
+
= @form.select @fieldname, @collection, @options, @options.merge(class: 'input__input')
|
12
|
+
- when :file
|
13
|
+
= @form.file_field @fieldname, @options.merge(class: 'input__input')
|
14
|
+
- when :text_area
|
15
|
+
= @form.text_area @fieldname, @options.merge(class: 'input__input')
|
16
|
+
- if @error_message
|
17
|
+
.input__errors = @error_message
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class InputComponent < ViewComponent::Base
|
2
|
+
include Alveole::Concerns::Bem
|
3
|
+
|
4
|
+
MODIFIERS = %i[disabled error].freeze
|
5
|
+
|
6
|
+
def initialize(type: nil, label: nil,
|
7
|
+
value: nil,
|
8
|
+
form: nil,
|
9
|
+
fieldname: nil,
|
10
|
+
collection: nil,
|
11
|
+
modifiers: [],
|
12
|
+
options: {})
|
13
|
+
super
|
14
|
+
|
15
|
+
@label = label
|
16
|
+
@form = form
|
17
|
+
@fieldname = fieldname
|
18
|
+
@collection = collection
|
19
|
+
@options = options
|
20
|
+
@options[:value] = value if value
|
21
|
+
@type = type || :text
|
22
|
+
@error_message = error_message
|
23
|
+
|
24
|
+
modifiers << :error if error?
|
25
|
+
modifiers << :disabled if options[:disabled]
|
26
|
+
self.modifiers = modifiers
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def error?
|
32
|
+
return false unless @form.object.respond_to? :errors
|
33
|
+
|
34
|
+
@error ||= @form.object.errors.include?(@fieldname.to_s.sub(/_id$/, ''))
|
35
|
+
end
|
36
|
+
|
37
|
+
def error_message
|
38
|
+
return unless error?
|
39
|
+
|
40
|
+
@error_message ||= @form.object.errors.messages_for(@fieldname.to_s.sub(/_id$/, '')).join(', ')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class NoticeComponent < ViewComponent::Base
|
2
|
+
TYPES = %w[notice alert].freeze
|
3
|
+
def initialize(title:, messages: [], type: nil)
|
4
|
+
super
|
5
|
+
|
6
|
+
@type = type if TYPES.include?(type)
|
7
|
+
@type ||= 'alert'
|
8
|
+
@title = title
|
9
|
+
@messages = messages
|
10
|
+
end
|
11
|
+
|
12
|
+
def render?
|
13
|
+
@messages.any?
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class TableColumnComponent < ViewComponent::Base
|
2
|
+
def initialize(value: nil, obj: nil, fieldname: nil, url: nil, options: {})
|
3
|
+
super
|
4
|
+
|
5
|
+
@obj = obj
|
6
|
+
@fieldname = fieldname
|
7
|
+
@value = value || obj&.send(fieldname)
|
8
|
+
@value = ApplicationController.helpers.format_value(@value, options)
|
9
|
+
@url = url
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Alveole
|
2
|
+
module Concerns
|
3
|
+
module Bem
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
const_set('COMPONENT_NAME', name.gsub('Component', '').underscore.dasherize)
|
8
|
+
const_set('MODIFIERS', [])
|
9
|
+
end
|
10
|
+
|
11
|
+
def modifiers=(values)
|
12
|
+
@bem_classes ||= []
|
13
|
+
@modifiers = values & self.class::MODIFIERS
|
14
|
+
|
15
|
+
@modifiers.each do |modifier|
|
16
|
+
@bem_classes << "#{self.class::COMPONENT_NAME}--#{modifier.to_s.dasherize}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails/engine'
|
2
|
+
require 'view_component/engine'
|
3
|
+
|
4
|
+
module Alveole
|
5
|
+
# :nodoc:
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
# isolate_namespace Primer::ViewComponents
|
8
|
+
|
9
|
+
config.autoload_once_paths = %W[
|
10
|
+
#{root}/lib/alveole/concerns
|
11
|
+
#{root}/lib/alveole/components
|
12
|
+
#{root}/lib/alveole/helpers
|
13
|
+
#{root}/lib/alveole/javascript
|
14
|
+
#{root}/lib/generators/
|
15
|
+
]
|
16
|
+
|
17
|
+
config.view_component.preview_paths << "#{Engine.root}/lib/alveole/previews"
|
18
|
+
config.view_component.show_previews_source = true
|
19
|
+
|
20
|
+
# config.primer_view_components = ActiveSupport::OrderedOptions.new
|
21
|
+
|
22
|
+
# config.primer_view_components.force_functional_colors = true
|
23
|
+
# config.primer_view_components.force_system_arguments = false
|
24
|
+
# config.primer_view_components.silence_deprecations = false
|
25
|
+
|
26
|
+
# initializer "primer_view_components.assets" do |app|
|
27
|
+
# app.config.assets.precompile += %w[primer_view_components] if app.config.respond_to?(:assets)
|
28
|
+
# end
|
29
|
+
end
|
30
|
+
end
|