Skip to content

Commit

Permalink
Merge pull request fs#162 from fs/html-views
Browse files Browse the repository at this point in the history
HTML / CSS / JS (RoR views)
  • Loading branch information
Nadezhda Shosheva authored Dec 12, 2023
2 parents ee5c37d + 8241f77 commit 490899f
Show file tree
Hide file tree
Showing 36 changed files with 516 additions and 208 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: main
on:
on:
push:
branches: [ "master" ]
pull_request:
Expand Down Expand Up @@ -35,6 +35,12 @@ jobs:
- name: Run rubocop
run: bin/rubocop

- name: Run slim linter
run: bin/slim-lint app/views

- name: Run scss linter
run: bin/scss-lint app/assets/stylesheets

- name: Run tests
run: bin/rspec
...
12 changes: 12 additions & 0 deletions .scss-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
scss_files: 'app/assets/stylesheets/**/*.scss'

linters:
BorderZero:
enabled: false

Indentation:
severity: warning
width: 2

PropertySortOrder:
enabled: false
36 changes: 36 additions & 0 deletions .slim-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
linters:
LineLength:
max: 120

RedundantDiv:
enabled: false

RuboCop:
enabled: true
# These cops are incredibly noisy since the Ruby we extract from Slim
# templates isn't well-formatted, so we ignore them.
ignored_cops:
- Layout/ArgumentAlignment
- Layout/HashAlignment
- Layout/IndentationWidth
- Layout/LineLength
- Layout/TrailingEmptyLines
- Lint/BlockAlignment
- Lint/EndAlignment
- Lint/Void
- Metrics/BlockLength
- Style/AlignParameters
- Style/BlockNesting
- Style/FileName
- Style/FirstParameterIndentation
- Style/FrozenStringLiteralComment
- Style/IfUnlessModifier
- Style/IndentationConsistency
- Style/IndentationWidth
- Style/Next
- Style/TrailingBlankLines
- Style/TrailingWhitespace
- Style/WhileUntilModifier
- Style/NestedTernaryOperator
- Style/StringLiterals
- Style/QuotedSymbols
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ gem "pg", "~> 1.1"
gem "puma", "~> 5.0"
# Use SCSS for stylesheets
gem "sass-rails", ">= 6"
gem "scss_lint"
gem "slim_lint"
gem "slim-rails"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem "webpacker", "~> 5.0"
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
Expand Down
21 changes: 21 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ GEM
ruby-next-core (0.15.3)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
Expand All @@ -288,6 +293,8 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
scss_lint (0.60.0)
sass (~> 3.5, >= 3.5.5)
selenium-webdriver (4.9.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
Expand All @@ -298,6 +305,16 @@ GEM
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
redis-client (>= 0.14.0)
slim (5.2.0)
temple (~> 0.10.0)
tilt (>= 2.1.0)
slim-rails (3.6.3)
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
slim_lint (0.24.0)
rubocop (>= 1.0, < 2.0)
slim (>= 3.0, < 6.0)
spring (4.1.1)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
Expand All @@ -306,6 +323,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
temple (0.10.3)
thor (1.2.2)
tilt (2.3.0)
timeout (0.4.0)
Expand Down Expand Up @@ -373,8 +391,11 @@ DEPENDENCIES
rubocop-rake
rubocop-thread_safety
sass-rails (>= 6)
scss_lint
selenium-webdriver (>= 4.0.0.rc1)
sidekiq
slim-rails
slim_lint
spring
turbolinks (~> 5)
tzinfo-data
Expand Down
7 changes: 7 additions & 0 deletions app/assets/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$black: #222;
$white: #fff;
$red: #f00;
$green: #008000;
$grey: #ccc;

$header-bg: #f1f1f1;
34 changes: 8 additions & 26 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
.center {
text-align: center;
}

.record {
border: 1px solid #000000;
padding: 10px;
margin-bottom: 10px;
}

.flash-alert {
color: red;
}
// Bootstrap
@import 'bootstrap/scss/bootstrap';

.flash-notice {
color: green;
}
@import 'variables';
@import 'reset';

.sort_links {
place-items: center;
display: flex;
margin-left: auto;
margin-right: auto;
}

.link {
font-family: "Courier New";
margin-left: auto;
margin-right: auto;
}
// Custom styles
@import 'base';
@import 'header';
@import 'form';
45 changes: 45 additions & 0 deletions app/assets/stylesheets/base.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.flash-alert {
color: $red;
}

.flash-notice {
color: $green;
}

.sort-links {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin: 1rem 0;

font-size: .75rem;
}

.link {
margin-left: auto;
margin-right: auto;
}

.content {
width: 100%;
padding: 1rem 2rem;
}

.title {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}

.table-actions {
display: flex;
justify-content: end;
flex-wrap: wrap;
gap: 1rem;
width: 100%;
}

.cursor-pointer {
cursor: pointer;
}
15 changes: 15 additions & 0 deletions app/assets/stylesheets/form.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.form {
display: flex;
flex-direction: column;
gap: 1rem;
max-width: 40rem;

&__field {
width: 100%;
}

&__actions {
display: flex;
justify-content: end;
}
}
10 changes: 10 additions & 0 deletions app/assets/stylesheets/header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.header {
display: flex;
gap: 1rem;
justify-content: flex-end;
align-items: center;

padding: 2rem;
background: $header-bg;
border-bottom: 1px solid $grey;
}
40 changes: 40 additions & 0 deletions app/assets/stylesheets/reset.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
* {
box-sizing: border-box;
}

html,
body {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font-family: Trebuchet MS,Lucida Grande,Lucida Sans Unicode,Lucida Sans,Tahoma,sans-serif;
vertical-align: baseline;
}

footer,
header,
menu,
nav,
section {
display: block;
}

body {
line-height: 1;
}

ol,
ul {
list-style: none;
}

blockquote,
q {
quotes: none;

&::before,
&::after {
content: '';
}
}
44 changes: 44 additions & 0 deletions app/javascript/components/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import _ from 'lodash';

class MyFunc {
constructor($el) {
this.$el = $el;
this.list = $el.querySelector('.js-projects-list');
this.items = this.$el.querySelectorAll('.js-item');

this.sortAscButton = this.$el.querySelector('.js-sort-by-title-asc');
this.sortDescButton = this.$el.querySelector('.js-sort-by-title-desc');

this.formattedItems = Array.from(this.items).map((item) => ({
id: JSON.parse(item.getAttribute('data-id')),
name: item.getAttribute('data-name'),
node: item,
}));

this.bindEvents(this.formattedItems);
}

bindEvents() {
this.sortAscButton.addEventListener('click', this.onSortByTitleASC);
this.sortDescButton.addEventListener('click', this.onSortByTitleDESC);
}

onSortByTitleASC = () => {
const sorteItemsByTitle = _.orderBy(this.formattedItems, ['name'], ['asc']);

sorteItemsByTitle.forEach((item) => this.list.appendChild(item.node));
this.sortAscButton.classList.add('d-none');
this.sortDescButton.classList.remove('d-none');
}

onSortByTitleDESC = () => {
const sorteItemsByTitle = _.orderBy(this.formattedItems, ['name'], ['desc']);

sorteItemsByTitle.forEach((item) => this.list.appendChild(item.node));

this.sortDescButton.classList.add('d-none');
this.sortAscButton.classList.remove('d-none');
}
}

export default MyFunc;
10 changes: 10 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"

import "bootstrap"

import MyFunc from 'components/script'

Rails.start()
Turbolinks.start()
ActiveStorage.start()

window.addEventListener("load", (event) => {
Array.from(document.querySelectorAll('.js-projects')).forEach(($el) => {
new MyFunc($el);
});
});
29 changes: 0 additions & 29 deletions app/views/layouts/application.html.erb

This file was deleted.

Loading

0 comments on commit 490899f

Please sign in to comment.