Skip to content

Commit

Permalink
try komponent gem
Browse files Browse the repository at this point in the history
  • Loading branch information
damienlethiec committed Feb 10, 2018
1 parent 3a42040 commit 7e5eb27
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 112 deletions.
8 changes: 0 additions & 8 deletions app/helpers/application_helper.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<%= csrf_meta_tags %>
<%= action_cable_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= stylesheet_pack_tag 'application', media: 'all' %>
</head>
<body>
<%= yield %>
Expand Down
4 changes: 1 addition & 3 deletions app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<%= c 'page' do %>
<p>Hello from our first component!</p>
<% end %>
<p>Hello from <%= Rails.application.class.parent_name %>!</p>
3 changes: 0 additions & 3 deletions frontend/components/page/_page.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/components/page/page.css

This file was deleted.

1 change: 0 additions & 1 deletion frontend/components/page/page.js

This file was deleted.

7 changes: 0 additions & 7 deletions frontend/init/index.css

This file was deleted.

1 change: 0 additions & 1 deletion frontend/init/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/packs/application.js

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/template.rb

This file was deleted.

35 changes: 0 additions & 35 deletions lib/generators/component_generator.rb

This file was deleted.

1 change: 0 additions & 1 deletion ruby-version.tt

This file was deleted.

78 changes: 39 additions & 39 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ def apply_template!
apply 'app/template.rb'
copy_file 'Procfile'

after_bundle do
setup_gems
install_optional_gems

setup_front_end
optional_options_front_end
setup_npm_packages
setup_front_end
optional_options_front_end
setup_npm_packages

install_optional_gems
setup_optional_gems
after_bundle do
setup_gems

run 'bundle binstubs bundler --force'

Expand Down Expand Up @@ -73,6 +72,7 @@ def setup_gems
setup_annotate
setup_bullet
setup_erd
setup_komponent if @komponent
end

def setup_friendly_id
Expand All @@ -98,63 +98,63 @@ def setup_erd
append_to_file '.gitignore', 'erd.pdf'
end

def setup_komponent
run 'rails g komponent:install --stimulus'
insert_into_file 'config/initializers/generators.rb', " g.komponent stimulus: true, locale: true\n", after: /uuid\n/
FileUtils.rm_rf 'app/javascript'
insert_into_file 'app/controllers/application_controller.rb', " prepend_view_path Rails.root.join('frontend')\n", after: /exception\n/
append_to_file 'Procfile', "assets: bin/webpack-dev-server\n"
end

def install_optional_gems
add_haml?
run 'bundle install'
end

def add_haml?
@haml = yes?('Do you want to use Haml instead of EBR?')
if @haml
if yes?('Do you want to use Haml instead of EBR?')
insert_into_file 'Gemfile', "gem 'haml'\n", after: /'friendly_id'\n/
insert_into_file 'Gemfile', "gem 'haml-rails'\n", after: /'friendly_id'\n/
run 'rake haml:erb2haml'
end
end

def setup_optional_gems
run 'rake haml:erb2haml' if @haml
end

def setup_front_end
copy_file '.browserslistrc'
copy_file 'app/assets/stylesheets/application.scss'
remove_file 'app/assets/stylesheets/application.ccs'
remove_file 'app/assets/stylesheets/application.css'
create_file 'app/javascript/packs/application.scss'
end

def optional_options_front_end
@fancy_front_end = yes?('Do you want to use a super fancy front-end setup from the future?')
if @fancy_front_end
remove_uneeded_stuff
add_fancy_setup
end
add_component_based_design
add_css_framework
end

def remove_uneeded_stuff
insert_into_file 'config/application.rb', "config.assets.enabled = false\n", after: /system_tests = nil\n/
comment_lines 'Gemfile', /uglifier/
comment_lines 'Gemfile', /sass/
run 'bundle install'
FileUtils.rm_rf 'app/assets'
def add_component_based_design
@komponent = yes?('Do you want to adopt a component based design for your front-end?')
if @komponent
insert_into_file 'Gemfile', "gem 'komponent'\n", after: /'friendly_id'\n/
end
end

def add_fancy_setup
FileUtils.rm_rf 'app/javascript'
apply 'frontend/template.rb'
gsub_file 'app/views/layouts/application.html.erb', "<%= javascript_include_tag 'application' %>\n", ''
gsub_file 'app/views/layouts/application.html.erb', 'stylesheet_link_tag', 'stylesheet_pack_tag'
gsub_file 'config/webpacker.yml', 'app/javascript', 'frontend'
insert_into_file 'app/controllers/application_controller.rb', " prepend_view_path Rails.root.join('frontend')\n", after: /exception\n/
copy_file 'app/helpers/application_helper.rb'
copy_file 'lib/generators/component_generator.rb'
append_to_file 'Procfile', "assets: bin/webpack-dev-server\n"
def setup_npm_packages
add_linters
end

def setup_npm_packages
run 'yarn add eslint babel-eslint eslint-config-airbnb-base eslint-config-prettier eslint-import-resolver-webpack eslint-plugin-import eslint-plugin-prettier lint-staged pre-commit prettier stylelint stylelint-config-standard--dev'
def add_linters
run 'yarn add eslint babel-eslint eslint-config-airbnb-base eslint-config-prettier eslint-import-resolver-webpack eslint-plugin-import eslint-plugin-prettier lint-staged prettier stylelint stylelint-config-standard --dev'
copy_file '.eslintrc'
copy_file '.stylelintrc'
run 'yarn add normalize.css'
run 'yarn install'
end

def add_css_framework
if yes?('Do you want to use Tailwind as a CSS framework?')
run 'yarn add tailwind'
run './node_modules/.bin/tailwind init frontend/init/css/tailwind.js'
# copy_file 'frontend/init/css/application.'
# append_to_file 'front/init/index.js', "import './css/tailwind.js';\n"
end
end

def setup_git
Expand Down

0 comments on commit 7e5eb27

Please sign in to comment.