komponent 2.2.0 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +14 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +10 -7
- data/.travis.yml +4 -5
- data/Appraisals +15 -0
- data/CHANGELOG.md +19 -1
- data/Gemfile +1 -0
- data/README.md +75 -25
- data/app/controllers/komponent/styleguide_controller.rb +20 -0
- data/app/views/komponent/styleguide/index.html.erb +9 -0
- data/app/views/komponent/styleguide/missing_template.html.erb +3 -0
- data/app/views/komponent/styleguide/show.html.erb +1 -0
- data/app/views/layouts/komponent.html.erb +17 -0
- data/config/routes.rb +5 -0
- data/komponent.gemspec +6 -5
- data/lib/generators/component/component_generator.rb +19 -3
- data/lib/generators/component/templates/examples.html.erb.erb +3 -0
- data/lib/generators/component/templates/examples.html.haml.erb +3 -0
- data/lib/generators/component/templates/examples.html.slim.erb +3 -0
- data/lib/generators/component/templates/stimulus_view.html.haml.erb +1 -1
- data/lib/generators/component/templates/view.html.haml.erb +1 -1
- data/lib/generators/komponent/examples_generator.rb +40 -0
- data/lib/generators/komponent/install_generator.rb +37 -41
- data/lib/generators/komponent/styleguide_generator.rb +41 -0
- data/lib/generators/komponent/templates/styleguide/components/container/_komponent_container.html.erb +3 -0
- data/lib/generators/komponent/templates/styleguide/components/container/komponent_container.css +17 -0
- data/lib/generators/komponent/templates/styleguide/components/container/komponent_container.js +1 -0
- data/lib/generators/komponent/templates/styleguide/components/container/komponent_container_component.rb +5 -0
- data/lib/generators/komponent/templates/styleguide/components/footer/_komponent_footer.html.erb +3 -0
- data/lib/generators/komponent/templates/styleguide/components/footer/komponent_footer.css +27 -0
- data/lib/generators/komponent/templates/styleguide/components/footer/komponent_footer.js +1 -0
- data/lib/generators/komponent/templates/styleguide/components/footer/komponent_footer_component.rb +5 -0
- data/lib/generators/komponent/templates/styleguide/components/header/_komponent_header.html.erb +3 -0
- data/lib/generators/komponent/templates/styleguide/components/header/komponent_header.css +15 -0
- data/lib/generators/komponent/templates/styleguide/components/header/komponent_header.js +1 -0
- data/lib/generators/komponent/templates/styleguide/components/header/komponent_header_component.rb +5 -0
- data/lib/generators/komponent/templates/styleguide/components/index.js +4 -0
- data/lib/generators/komponent/templates/styleguide/components/sidebar/_komponent_sidebar.html.erb +10 -0
- data/lib/generators/komponent/templates/styleguide/components/sidebar/komponent_sidebar.css +43 -0
- data/lib/generators/komponent/templates/styleguide/components/sidebar/komponent_sidebar.js +1 -0
- data/lib/generators/komponent/templates/styleguide/components/sidebar/komponent_sidebar_component.rb +5 -0
- data/lib/generators/komponent/templates/styleguide/packs/komponent.js +2 -0
- data/lib/generators/komponent/utils.rb +49 -0
- data/lib/komponent.rb +2 -2
- data/lib/komponent/component.rb +55 -0
- data/lib/komponent/component_path_resolver.rb +6 -6
- data/lib/komponent/component_renderer.rb +3 -1
- data/lib/komponent/{railtie.rb → engine.rb} +21 -1
- data/lib/komponent/komponent_helper.rb +29 -0
- data/lib/komponent/rails/tasks/komponent.rake +12 -0
- data/lib/komponent/translation.rb +15 -3
- data/lib/komponent/version.rb +1 -1
- metadata +62 -18
- data/gemfiles/Gemfile-rails.4.2.x +0 -8
- data/gemfiles/Gemfile-rails.5.0.x +0 -8
- data/gemfiles/Gemfile-rails.5.1.x +0 -8
- data/gemfiles/Gemfile-rails.5.2.x +0 -8
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1>Styleguide</h1>
|
2
|
+
|
3
|
+
<% if components.any? %>
|
4
|
+
<p>Select one of the components from the side to view its examples and documentation.</p>
|
5
|
+
<% else %>
|
6
|
+
<p><<strong>Hint:</strong> You haven't created any component yet</h2>
|
7
|
+
<p>You can generate your first component by running:</p>
|
8
|
+
<pre>rails generate component component-name</pre>
|
9
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render partial: @component.examples_view %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Styleguide</title>
|
5
|
+
<%= javascript_pack_tag 'komponent' %>
|
6
|
+
<%= stylesheet_pack_tag 'komponent', media: 'all' %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= c 'komponent/header' %>
|
11
|
+
<%= c 'komponent/sidebar' %>
|
12
|
+
<%= c 'komponent/container' do %>
|
13
|
+
<%= yield %>
|
14
|
+
<% end %>
|
15
|
+
<%= c 'komponent/footer' %>
|
16
|
+
</body>
|
17
|
+
</html>
|
data/config/routes.rb
ADDED
data/komponent.gemspec
CHANGED
@@ -23,16 +23,17 @@ Gem::Specification.new do |spec|
|
|
23
23
|
}
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
f.match(%r{^(test|spec|features|fixtures)/})
|
26
|
+
f.match(%r{^(test|spec|features|fixtures|gemfiles)/})
|
27
27
|
end
|
28
28
|
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
spec.required_ruby_version = '>= 2.2.0'
|
31
31
|
|
32
|
-
spec.add_dependency "actionview", ">=
|
33
|
-
spec.add_dependency "activesupport", ">=
|
34
|
-
spec.add_dependency "railties", ">=
|
32
|
+
spec.add_dependency "actionview", ">= 5.0"
|
33
|
+
spec.add_dependency "activesupport", ">= 5.0"
|
34
|
+
spec.add_dependency "railties", ">= 5.0"
|
35
35
|
spec.add_dependency "webpacker", ">= 3.0.0"
|
36
36
|
|
37
|
-
spec.add_development_dependency "
|
37
|
+
spec.add_development_dependency "appraisal"
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0.1"
|
38
39
|
end
|
@@ -34,6 +34,10 @@ class ComponentGenerator < Rails::Generators::NamedBase
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
def create_examples_view_file
|
38
|
+
template "examples.html.#{template_engine}.erb", component_path + "_examples.html.#{template_engine}"
|
39
|
+
end
|
40
|
+
|
37
41
|
def import_to_packs
|
38
42
|
root_path = default_path
|
39
43
|
base_path = root_path + "components"
|
@@ -169,14 +173,26 @@ class ComponentGenerator < Rails::Generators::NamedBase
|
|
169
173
|
end
|
170
174
|
|
171
175
|
def sort_lines_alphabetically!(path)
|
176
|
+
relative_imports, imports = read_imports_from_path(path)
|
177
|
+
|
178
|
+
return if imports.empty?
|
179
|
+
|
180
|
+
imports = imports.uniq.sort + relative_imports
|
181
|
+
|
182
|
+
write_imports_to_path(imports, path)
|
183
|
+
end
|
184
|
+
|
185
|
+
def read_imports_from_path(path)
|
172
186
|
lines = File.readlines(path).map do |line|
|
173
187
|
line if line =~ /^import ["'](.*)["'];$/
|
174
188
|
end.compact
|
175
189
|
|
176
|
-
|
177
|
-
|
178
|
-
|
190
|
+
lines.partition do |l|
|
191
|
+
l =~ /^import ["']\.(.*)["'];$/
|
192
|
+
end
|
193
|
+
end
|
179
194
|
|
195
|
+
def write_imports_to_path(lines, path)
|
180
196
|
File.open(path, "w") do |f|
|
181
197
|
lines.each do |line|
|
182
198
|
f.write(line)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'komponent/component'
|
4
|
+
require File.expand_path('../utils', __FILE__)
|
5
|
+
|
6
|
+
module Komponent
|
7
|
+
module Generators
|
8
|
+
class ExamplesGenerator < Rails::Generators::Base
|
9
|
+
include Utils
|
10
|
+
|
11
|
+
source_root File.expand_path('../../component/templates', __FILE__)
|
12
|
+
|
13
|
+
def create_examples_files
|
14
|
+
Komponent::Component.all.each do |name, component|
|
15
|
+
create_examples_view_file(name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def split_name(name)
|
22
|
+
name.split(/[:,::,\/]/).reject(&:blank?).map(&:underscore)
|
23
|
+
end
|
24
|
+
|
25
|
+
def component_path(component_name)
|
26
|
+
path_parts = [default_path, 'components', *split_name(component_name)]
|
27
|
+
|
28
|
+
Pathname.new(path_parts.join('/'))
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def create_examples_view_file(component_name)
|
34
|
+
@component_name = split_name(component_name).last.underscore
|
35
|
+
|
36
|
+
template "examples.html.#{template_engine}.erb", component_path(component_name) + "_examples.html.#{template_engine}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,51 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rails/generators'
|
4
|
+
|
3
5
|
module Komponent
|
4
6
|
module Generators
|
5
7
|
class InstallGenerator < Rails::Generators::Base
|
6
8
|
class_option :stimulus, type: :boolean, default: false
|
9
|
+
source_root File.join(File.dirname(__FILE__), "templates")
|
7
10
|
|
8
|
-
def
|
9
|
-
return if
|
10
|
-
|
11
|
-
|
12
|
-
raise Thor::Error, dependencies_not_met_error_message
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def create_root_directory
|
17
|
-
return if File.directory?(komponent_root_directory)
|
18
|
-
|
19
|
-
empty_directory(komponent_root_directory)
|
11
|
+
def check_webpacker_installed
|
12
|
+
return if File.directory?(komponent_directory)
|
13
|
+
installed = File.exist?(webpacker_configuration_file)
|
14
|
+
raise Thor::Error, dependencies_not_met_error_message unless installed
|
20
15
|
end
|
21
16
|
|
22
|
-
def
|
23
|
-
|
17
|
+
def create_komponent_directory
|
18
|
+
empty_directory(komponent_directory)
|
19
|
+
directory(
|
20
|
+
javascript_directory,
|
21
|
+
komponent_directory,
|
22
|
+
recursive: true,
|
23
|
+
)
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def alter_webpacker_configuration
|
27
|
+
gsub_file(
|
28
|
+
webpacker_configuration_file,
|
29
|
+
/source_path: app\/javascript$/,
|
30
|
+
"source_path: #{komponent_directory}",
|
31
|
+
)
|
30
32
|
end
|
31
33
|
|
32
34
|
def create_komponent_default_structure
|
33
|
-
return if File.exist?(
|
34
|
-
|
35
|
+
return if File.exist?(join(components_directory, "index.js"))
|
35
36
|
empty_directory(components_directory)
|
36
|
-
create_file(
|
37
|
+
create_file(join(components_directory, "index.js"))
|
37
38
|
end
|
38
39
|
|
39
40
|
def create_stimulus_file
|
40
41
|
return if File.exist?(stimulus_application_path)
|
41
42
|
return unless stimulus?
|
42
|
-
|
43
43
|
create_file(stimulus_application_path, stimulus_application_template)
|
44
44
|
end
|
45
45
|
|
46
46
|
def append_to_application_configuration
|
47
|
-
application "config.autoload_paths << config.root.join('#{
|
48
|
-
application "config.i18n.load_path += Dir[config.root.join('#{
|
47
|
+
application "config.autoload_paths << config.root.join('#{komponent_directory}/components')"
|
48
|
+
application "config.i18n.load_path += Dir[config.root.join('#{komponent_directory}/components/**/*.*.yml')]"
|
49
49
|
end
|
50
50
|
|
51
51
|
def append_to_application_pack
|
@@ -73,31 +73,27 @@ export default application;
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def stimulus_application_path
|
76
|
-
|
76
|
+
join(komponent_directory, "stimulus_application.js")
|
77
77
|
end
|
78
78
|
|
79
79
|
def application_pack_path
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
def komponent_root_directory
|
84
|
-
default_path
|
80
|
+
join(komponent_directory, "packs", "application.js")
|
85
81
|
end
|
86
82
|
|
87
83
|
def components_directory
|
88
|
-
|
84
|
+
join(komponent_directory, "components")
|
89
85
|
end
|
90
86
|
|
91
|
-
def
|
92
|
-
|
87
|
+
def komponent_directory
|
88
|
+
default_path
|
93
89
|
end
|
94
90
|
|
95
|
-
def
|
96
|
-
|
91
|
+
def webpacker_configuration_file
|
92
|
+
join("config", "webpacker.yml")
|
97
93
|
end
|
98
94
|
|
99
|
-
def
|
100
|
-
|
95
|
+
def javascript_directory
|
96
|
+
join("app", "javascript")
|
101
97
|
end
|
102
98
|
|
103
99
|
def dependencies_not_met_error_message
|
@@ -113,10 +109,6 @@ export default application;
|
|
113
109
|
rails_configuration.komponent.root
|
114
110
|
end
|
115
111
|
|
116
|
-
def relative_path_from_rails
|
117
|
-
default_path.relative_path_from(Rails.root)
|
118
|
-
end
|
119
|
-
|
120
112
|
private
|
121
113
|
|
122
114
|
def komponent_configuration
|
@@ -133,6 +125,10 @@ export default application;
|
|
133
125
|
def app_generators
|
134
126
|
rails_configuration.app_generators
|
135
127
|
end
|
128
|
+
|
129
|
+
def join(*paths)
|
130
|
+
File.expand_path(File.join(*paths), destination_root)
|
131
|
+
end
|
136
132
|
end
|
137
133
|
end
|
138
134
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('../utils', __FILE__)
|
4
|
+
|
5
|
+
module Komponent
|
6
|
+
module Generators
|
7
|
+
class StyleguideGenerator < Rails::Generators::Base
|
8
|
+
include Utils
|
9
|
+
|
10
|
+
source_root File.expand_path('../templates/styleguide', __FILE__)
|
11
|
+
|
12
|
+
def check_komponent_dependency
|
13
|
+
unless komponent_already_installed?
|
14
|
+
raise Thor::Error, dependencies_not_met_error_message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_styleguide_components
|
19
|
+
directory 'components', components_directory.join('komponent')
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_komponent_pack
|
23
|
+
template 'packs/komponent.js', komponent_pack_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_to_application_routes
|
27
|
+
route 'mount Komponent::Engine => \'/\' if Rails.env.development?'
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def komponent_pack_path
|
33
|
+
komponent_root_directory.join('packs', 'komponent.js')
|
34
|
+
end
|
35
|
+
|
36
|
+
def dependencies_not_met_error_message
|
37
|
+
'Seems you don\'t have komponent installed in your project. Please install komponent, and follow instructions at https://github.com/komposable/komponent'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/generators/komponent/templates/styleguide/components/container/komponent_container.css
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
/* stylelint-disable value-list-comma-newline-after */
|
2
|
+
|
3
|
+
.komponent-container {
|
4
|
+
font-size: 16px;
|
5
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
6
|
+
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
7
|
+
margin: 40px 60px 0 300px;
|
8
|
+
|
9
|
+
.komponent-code {
|
10
|
+
background-color: #333;
|
11
|
+
color: #fff;
|
12
|
+
margin: 10px 0;
|
13
|
+
padding: 10px;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
/* stylelint-enable */
|
data/lib/generators/komponent/templates/styleguide/components/container/komponent_container.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import "./komponent_container.css";
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/* stylelint-disable value-list-comma-newline-after */
|
2
|
+
|
3
|
+
.komponent-footer {
|
4
|
+
bottom: 30px;
|
5
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
6
|
+
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
7
|
+
font-size: 14px;
|
8
|
+
position: fixed;
|
9
|
+
right: 30px;
|
10
|
+
text-align: center;
|
11
|
+
|
12
|
+
&,
|
13
|
+
a {
|
14
|
+
color: #999;
|
15
|
+
}
|
16
|
+
|
17
|
+
a {
|
18
|
+
text-decoration: none;
|
19
|
+
|
20
|
+
&:hover,
|
21
|
+
&:focus {
|
22
|
+
color: #0038ea;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
/* stylelint-enable */
|
@@ -0,0 +1 @@
|
|
1
|
+
import "./komponent_footer.css";
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/* stylelint-disable value-list-comma-newline-after */
|
2
|
+
|
3
|
+
.komponent-header {
|
4
|
+
align-items: center;
|
5
|
+
background-color: #0038ea;
|
6
|
+
color: white;
|
7
|
+
display: flex;
|
8
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
9
|
+
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
10
|
+
font-size: 16px;
|
11
|
+
height: 60px;
|
12
|
+
padding: 0 20px;
|
13
|
+
}
|
14
|
+
|
15
|
+
/* stylelint-enable */
|