Skip to content

Commit

Permalink
Merge 86d07f9 into 0685c5c
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Aug 24, 2018
2 parents 0685c5c + 86d07f9 commit 87954df
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 102 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always

Style/StringLiterals:
EnforcedStyle: single_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: single_quotes

Naming/ConstantName:
Enabled: true

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Upcoming release

**Enhancements:**
- Cleanup code by following some ruby conventions

**Breaking changes:**
- Dropped support for Rails 4.2

Expand Down
20 changes: 10 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
git_source(:github) {|repo_name| 'https://github.com/#{repo_name}' }

# Specify your gem's dependencies in komponent.gemspec
gemspec

gem "rails"
gem "rake", ">= 11.1"
gem "rubocop", require: false
gem "webpacker"
gem 'rails'
gem 'rake', '>= 11.1'
gem 'rubocop', require: false
gem 'webpacker'

group :test do
gem "aruba"
gem "cucumber"
gem "simplecov", require: false
gem "coveralls", require: false
gem 'aruba'
gem 'coveralls', require: false
gem 'cucumber'
gem 'simplecov', require: false
end
24 changes: 12 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rubocop/rake_task"
require "rake/testtask"
require "cucumber"
require "cucumber/rake/task"
require "coveralls/rake/task"
require 'bundler/gem_tasks'
require 'rubocop/rake_task'
require 'rake/testtask'
require 'cucumber'
require 'cucumber/rake/task'
require 'coveralls/rake/task'

namespace :test do
task all: [:rubocop, :unit, :cucumber]
task all_with_coverage: [:all, "coveralls:push"]
task all_with_coverage: [:all, 'coveralls:push']

RuboCop::RakeTask.new

Rake::TestTask.new(:unit) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
t.warning = false
end

Cucumber::Rake::Task.new(:cucumber) do |t|
t.cucumber_opts = "--format pretty"
t.cucumber_opts = '--format pretty'
end

Coveralls::RakeTask.new
end

task test: "test:all"
task test: 'test:all'

task default: :test
8 changes: 4 additions & 4 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "komponent"
require 'bundler/setup'
require 'komponent'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# require 'pry'
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
40 changes: 20 additions & 20 deletions komponent.gemspec
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
# frozen_string_literal: true

lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "komponent/version"
require 'komponent/version'

Gem::Specification.new do |spec|
spec.name = "komponent"
spec.name = 'komponent'
spec.version = Komponent::VERSION
spec.authors = ["Ouvrages"]
spec.email = ["contact@ouvrages-web.fr"]
spec.authors = ['Ouvrages']
spec.email = ['contact@ouvrages-web.fr']

spec.summary = "An opinionated way of organizing front-end code in Ruby on Rails, based on components"
spec.description = "An opinionated way of organizing front-end code in Ruby on Rails, based on components"
spec.homepage = "http://komponent.io"
spec.license = "MIT"
spec.summary = 'An opinionated way of organizing front-end code in Ruby on Rails, based on components'
spec.description = 'An opinionated way of organizing front-end code in Ruby on Rails, based on components'
spec.homepage = 'http://komponent.io'
spec.license = 'MIT'

spec.metadata = {
"homepage_uri" => "http://komponent.io",
"changelog_uri" => "https://github.com/komposable/komponent/blob/master/CHANGELOG.md",
"source_code_uri" => "https://github.com/komposable/komponent",
"bug_tracker_uri" => "https://github.com/komposable/komponent/issues",
'homepage_uri' => 'http://komponent.io',
'changelog_uri' => 'https://github.com/komposable/komponent/blob/master/CHANGELOG.md',
'source_code_uri' => 'https://github.com/komposable/komponent',
'bug_tracker_uri' => 'https://github.com/komposable/komponent/issues',
}

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features|fixtures)/})
end

spec.require_paths = ["lib"]
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.2.0'

spec.add_dependency "actionview", ">= 5.0"
spec.add_dependency "activesupport", ">= 5.0"
spec.add_dependency "railties", ">= 5.0"
spec.add_dependency "webpacker", ">= 3.0.0"
spec.add_dependency 'actionview', '>= 5.0'
spec.add_dependency 'activesupport', '>= 5.0'
spec.add_dependency 'railties', '>= 5.0'
spec.add_dependency 'webpacker', '>= 3.0.0'

spec.add_development_dependency "appraisal"
spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'bundler', '~> 1.15'
end
44 changes: 22 additions & 22 deletions lib/generators/component/component_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,61 @@ def create_css_file
end

def create_js_file
template "js.erb", component_path + "#{name_with_namespace}.js"
template 'js.erb', component_path + "#{name_with_namespace}.js"
if stimulus?
template "stimulus_controller_js.erb", component_path + "#{name_with_namespace}_controller.js"
template 'stimulus_controller_js.erb', component_path + "#{name_with_namespace}_controller.js"
end
end

def create_rb_file
template "rb.erb", component_path + "#{module_name.underscore}.rb"
template 'rb.erb', component_path + "#{module_name.underscore}.rb"
end

def create_locale_files
return unless locale?

I18n.available_locales.each do |locale|
@locale = locale
template "locale.erb", component_path + "#{name_with_namespace}.#{locale}.yml"
template 'locale.erb', component_path + "#{name_with_namespace}.#{locale}.yml"
end
end

def import_to_packs
root_path = default_path
base_path = root_path + "components"
base_path = root_path + 'components'

imports = []

split_name[0..-2].each do |split|
base_path += split
file_path = base_path + "index.js"
file_path = base_path + 'index.js'
create_file(file_path) unless File.exist?(file_path)
imports << base_path.relative_path_from(root_path)
end

root_path_dup = root_path.dup

[Pathname.new("components"), *split_name[0..-2]].each do |split|
[Pathname.new('components'), *split_name[0..-2]].each do |split|
root_path_dup += split
import = imports.shift
if import
append_to_file(root_path_dup + "index.js") do
append_to_file(root_path_dup + 'index.js') do
"\nimport \"#{import}\";\n"
end
sort_lines_alphabetically!(root_path_dup + "index.js")
sort_lines_alphabetically!(root_path_dup + 'index.js')
end
end

append_to_file(base_path + "index.js") do
append_to_file(base_path + 'index.js') do
"\nimport \"#{base_path.relative_path_from(root_path)}/#{component_name}/#{name_with_namespace.underscore}\";\n"
end
sort_lines_alphabetically!(base_path + "index.js")
sort_lines_alphabetically!(base_path + 'index.js')
end

def clear_component
return unless destroying?

base_path = default_path + "components"
base_path = default_path + 'components'
base_path_dup = base_path.dup

paths = split_name[0..-2].map do |split|
Expand All @@ -81,40 +81,40 @@ def clear_component
FileUtils.rm_rf(component_path)

Dir.chdir(path)
directories = Dir.glob("*").select do |entry|
directories = Dir.glob('*').select do |entry|
File.directory?(entry)
end

if directories.size == 0
FileUtils.rm_rf(path)
remove_line!(base_path + "index.js", split)
remove_line!(base_path + 'index.js', split)
else
remove_line!(path + "index.js", component_name)
remove_line!(path + 'index.js', component_name)
end
end

FileUtils.rm_rf(component_path)
remove_line!(base_path + "index.js", component_name)
remove_line!(base_path + 'index.js', component_name)
end

protected

def template_prefix
stimulus? ? "stimulus_" : ""
stimulus? ? 'stimulus_' : ''
end

def split_name
name.split(/[:,::,\/]/).reject(&:blank?).map(&:underscore)
end

def name_with_namespace
split_name.join("_")
split_name.join('_')
end

def component_path
path_parts = [default_path, "components", *split_name]
path_parts = [default_path, 'components', *split_name]

Pathname.new(path_parts.join("/"))
Pathname.new(path_parts.join('/'))
end

def module_name
Expand Down Expand Up @@ -177,7 +177,7 @@ def sort_lines_alphabetically!(path)

lines = lines.uniq.sort

File.open(path, "w") do |f|
File.open(path, 'w') do |f|
lines.each do |line|
f.write(line)
end
Expand All @@ -189,7 +189,7 @@ def remove_line!(path, component_name)
line unless line =~ /#{component_name}/
end.compact

File.open(path, "w") do |f|
File.open(path, 'w') do |f|
lines.each do |line|
f.write(line)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/component/templates/js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import application from "stimulus_application";
import { definitionsFromContext } from "stimulus/webpack-helpers";
import "./<%= name_with_namespace %>.<%= stylesheet_engine %>";

const context = require.context('./', true, /_controller\.js$/);
const context = require.context("./'" true, /_controller\.js$/);
application.load(definitionsFromContext(context));
<%- else -%>
import "./<%= name_with_namespace %>.<%= stylesheet_engine %>";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div data-controller="<%= component_class_name %>" class="<%= component_class_name %>">
<%- if locale? -%>
<%%= t ".component_name" %>
<%%= t '.component_name' %>
<%- else -%>
<%= module_name.underscore %>
<%- end -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.<%= component_class_name %>{ data: { controller: '<%= component_class_name %>' } }
<%- if locale? -%>
= t ".component_name"
= t '.component_name'
<%- else -%>
<%= module_name.underscore %>
<%- end -%>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.<%= component_class_name %>(data-controller="<%= component_class_name %>")
.<%= component_class_name %>(data-controller='<%= component_class_name %>')
<%- if locale? -%>
= t ".component_name"
= t '.component_name'
<%- else -%>
| <%= module_name.underscore %>
<%- end -%>
2 changes: 1 addition & 1 deletion lib/generators/component/templates/view.html.erb.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="<%= component_class_name %>">
<%- if locale? -%>
<%%= t ".component_name" %>
<%%= t '.component_name' %>
<%- else -%>
<%= component_name.underscore %>
<%- end -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/component/templates/view.html.haml.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.<%= component_class_name %>
<%- if locale? -%>
= t ".component_name"
= t '.component_name'
<%- else -%>
<%= component_name.underscore %>
<%- end -%>
2 changes: 1 addition & 1 deletion lib/generators/component/templates/view.html.slim.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.<%= component_class_name %>
<%- if locale? -%>
= t ".component_name"
= t '.component_name'
<%- else -%>
| <%= component_name.underscore %>
<%- end -%>
Loading

0 comments on commit 87954df

Please sign in to comment.