Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front-end with components #7

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
run: |
gem install bundler
bundle install
bundle exec rubocop
bundle exec rubocop
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "rubocop-rails-omakase"
Expand Down
7 changes: 6 additions & 1 deletion application/Gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ gem 'discard', '~> 1.2'

<%= %Q{gem 'graphql'\n} if requires_graphql? -%>

gem "inline_svg"

gem "meta-tags"
gem 'mjml-rails'

gem 'pg'
<%= %Q{gem 'propshaft'\n} unless api? -%>
gem 'puma'
Expand Down Expand Up @@ -62,4 +67,4 @@ end

group :test do
gem 'simplecov', require: false
end
end
16 changes: 0 additions & 16 deletions application/app/assets/controllers/application/index.js.tt

This file was deleted.

21 changes: 21 additions & 0 deletions application/app/assets/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { registerControllers } from 'stimulus-vite-helpers'
import Autosave from 'stimulus-rails-autosave'
import {
Alert,
Dropdown,
Toggle,
Modal
} from 'tailwindcss-stimulus-components'
import TextareaAutogrow from 'stimulus-textarea-autogrow'

import { stimulus } from '~/init'

stimulus.register('alert', Alert)
stimulus.register('autosave', Autosave)
stimulus.register('dropdown', Dropdown)
stimulus.register('modal-sync', Modal)
stimulus.register('toggle', Toggle)
stimulus.register('textarea-autogrow', TextareaAutogrow)

const controllers = import.meta.glob('./**/*_controller.js', { eager: true })
registerControllers(stimulus, controllers)
15 changes: 15 additions & 0 deletions application/app/assets/controllers/modal_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Modal } from 'tailwindcss-stimulus-components'

export default class ModalController extends Modal {
static targets = ['turboFrame']

close () {
super.close()
this.dispatch('close')

if (this.hasTurboFrameTarget) {
this.turboFrameTarget.src = null
this.turboFrameTarget.innerHTML = ''
}
}
}
8 changes: 8 additions & 0 deletions application/app/assets/entrypoints/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@import "tailwindcss/base";
@import "../stylesheets/base.css";
@import "../stylesheets/vendors";

@import "tailwindcss/components";
@import "../stylesheets/components.css";

@import "tailwindcss/utilities";
3 changes: 0 additions & 3 deletions application/app/assets/entrypoints/application.css.tt

This file was deleted.

2 changes: 2 additions & 0 deletions application/app/assets/entrypoints/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '~/init'
import '~/controllers'
2 changes: 0 additions & 2 deletions application/app/assets/entrypoints/application.js.tt

This file was deleted.

20 changes: 20 additions & 0 deletions application/app/assets/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added application/app/assets/images/og.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions application/app/assets/init/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './stimulus'
import './turbo'

export { stimulus } from './stimulus'
4 changes: 0 additions & 4 deletions application/app/assets/init/index.js.tt

This file was deleted.

8 changes: 8 additions & 0 deletions application/app/assets/init/stimulus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Application } from '@hotwired/stimulus'

const stimulus = Application.start()

window.Stimulus = stimulus
stimulus.debug = new URLSearchParams(window.location.search).has('debug')

export { stimulus }
8 changes: 0 additions & 8 deletions application/app/assets/init/stimulus.js.tt

This file was deleted.

4 changes: 4 additions & 0 deletions application/app/assets/init/turbo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import '@hotwired/turbo-rails'
import * as Turbo from '@hotwired/turbo'

Turbo.setProgressBarDelay(500)
3 changes: 0 additions & 3 deletions application/app/assets/init/turbo.js.tt

This file was deleted.

5 changes: 5 additions & 0 deletions application/app/assets/stylesheets/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@layer base {
body {
@apply antialiased;
}
}
4 changes: 4 additions & 0 deletions application/app/assets/stylesheets/components.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import "./components/body.css";
@import "./components/navbar.css";
@import "./components/wysiwyg.css";
@import "./components/wrapper.css";
Empty file.
13 changes: 13 additions & 0 deletions application/app/assets/stylesheets/components/body.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@layer components {
.body {
@apply flex flex-col min-h-screen;
}

.body__main {
@apply flex-1 pt-6;
}

.body__footer {
@apply py-8 text-gray-600;
}
}
25 changes: 25 additions & 0 deletions application/app/assets/stylesheets/components/navbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@layer components {
.navbar {
@apply sticky top-0 transition-all bg-white shadow-sm bg-opacity-90 backdrop-blur-sm;
}

.navbar__logo {
@apply w-auto h-7;
}

.navbar__inner {
@apply flex items-center wrapper;
}

.navbar__menu{
@apply flex flex-1 ml-8 space-x-6;
}

.navbar__link {
@apply flex items-center justify-between py-4 text-base font-semibold text-black hover:text-gray-500;
}

.navbar__link-active {
@apply text-gray-500;
}
}
9 changes: 9 additions & 0 deletions application/app/assets/stylesheets/components/wrapper.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@layer components {
.wrapper {
@apply px-3 mx-auto max-w-7xl sm:px-6;
}

.wrapper-narrow {
@apply max-w-4xl
}
}
6 changes: 6 additions & 0 deletions application/app/assets/stylesheets/components/wysiwyg.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@layer components {
.wysiwyg {
/* https://tailwindcss.com/docs/typography-plugin */
@apply prose;
}
}
9 changes: 0 additions & 9 deletions application/app/assets/stylesheets/tailwindcss.css.tt

This file was deleted.

13 changes: 13 additions & 0 deletions application/app/components/application_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ApplicationComponent < ViewComponent::Base
include Turbo::FramesHelper

def initialize(tag: nil, classes: nil, **options)
@tag = tag || :div
@classes = classes
@options = options
end

def call
content_tag(@tag, content, class: @classes, **@options) if @tag
end
end
32 changes: 32 additions & 0 deletions application/app/components/ui/flash/component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%= turbo_frame_tag :flash,
class: "fixed flex flex-col space-y-2 top-12 right-3 sm:right-6 w-fit",
data: { turbo_temporary: "true" } do %>
<% flash.each do |key, message| %>
<div
class="max-w-sm w-full sm:min-w-96 px-1 py-1 rounded border-l-4 transition duration-300 transform hidden <%= tailwind_classes_for(key) %>"
data-controller="alert"
data-alert-dismiss-after-value="<%= DISMISS_AFTER %>"
data-alert-remove-delay-value="<%= REMOVE_DELAY %>"
data-alert-show-delay-value="<%= SHOW_DELAY %>"
data-transition-enter-from="opacity-0 translate-x-1/4"
data-transition-enter-to="opacity-100 translate-x-0"
data-transition-leave-from="opacity-100 translate-x-0"
data-transition-leave-to="opacity-0 translate-x-1/4">

<div class="p-2">
<div class="flex items-start">
<p class="flex-1 text-sm">
<%= sanitize(message) %>
</p>
<div class="flex flex-shrink-0 ml-4 mt-0.5">
<button class="inline-flex text-gray-400 transition duration-300 focus:outline-none focus:text-gray-600 hover:text-gray-600" type="button" data-action="alert#close" aria-label="Close alert">
<svg class="w-4 h-4" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd">
</svg>
</button>
</div>
</div>
</div>
</div>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions application/app/components/ui/flash/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Alert } from 'tailwindcss-stimulus-components'
import { stimulus } from '~/init'

stimulus.register('alert', Alert)
16 changes: 16 additions & 0 deletions application/app/components/ui/flash/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Ui::Flash::Component < ApplicationComponent
DISMISS_AFTER = 5000
REMOVE_DELAY = 6000
SHOW_DELAY = 0

protected

def tailwind_classes_for(flash_type)
{
notice: "bg-green-100 border-green-300",
success: "bg-green-100 border-green-300",
alert: "bg-red-100 border-red-300",
error: "bg-red-100 border-red-300"
}.stringify_keys[flash_type.to_s] || flash_type.to_s
end
end
15 changes: 12 additions & 3 deletions application/app/controllers/home_controller.rb.tt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# frozen_string_literal: true

class HomeController < ApplicationController
def index
unless api?
flash.now[:success] = "Flash message example"
end
<%= %Q{render json: { message: 'Hello from JetRockets' }\n} if api? -%>
end
end

unless api?
def terms
end

def privacy
end
end
end
16 changes: 16 additions & 0 deletions application/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module ApplicationHelper
def component(name, *args, **kwargs, &block)
component = name.to_s.camelize.constantize::Component
render(component.new(*args, **kwargs), &block)
end

def inline_svg_vite_tag(filename, transform_params = {})
with_asset_finder(InlineSvg::ViteAssetFinder) do
render_inline_svg(filename, transform_params)
end
end

def vite_asset_url_with_host(source)
URI.join(root_url, vite_asset_url(source))
end
end
54 changes: 54 additions & 0 deletions application/app/helpers/meta_tags_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module MetaTagsHelper
def default_meta_tags
og_title = meta_tags[:title] || default_title
og_description = meta_tags[:description] || default_description

{
site: site_name,
title: default_title,
description: default_description,
keywords: default_keywords,
canonical: request.original_url,
reverse: true,
og: {
title: og_title,
type: "website",
description: og_description,
image: {
_: vite_asset_url_with_host("images/og.jpg"),
width: 1200,
height: 630
},
url: request.url,
site_name: site_name,
locale: :en_US
},
twitter: {
card: "summary_large_image",
site: "@twitter_account",
title: og_title,
description: og_description,
image: vite_asset_url_with_host("images/og.jpg"),
url: request.url
}
}
end

private

def site_name
"Site Name"
end

def default_title
"Default Title"
end

def default_description
"Default Description"
end

def default_keywords
"Default keywords"
end
end
Loading
Loading