Initial commit
This commit is contained in:
commit
0cec39413f
116 changed files with 9683 additions and 0 deletions
2
app/assets/config/manifest.js
Normal file
2
app/assets/config/manifest.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
//= link_tree ../images
|
||||
//= link_directory ../stylesheets .css
|
0
app/assets/images/.keep
Normal file
0
app/assets/images/.keep
Normal file
2
app/assets/stylesheets/application.scss
Normal file
2
app/assets/stylesheets/application.scss
Normal file
|
@ -0,0 +1,2 @@
|
|||
@import "materialize";
|
||||
@import "https://fonts.googleapis.com/icon?family=Material+Icons";
|
3
app/assets/stylesheets/books.scss
Normal file
3
app/assets/stylesheets/books.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the Books controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: https://sass-lang.com/
|
4
app/channels/application_cable/channel.rb
Normal file
4
app/channels/application_cable/channel.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
end
|
4
app/channels/application_cable/connection.rb
Normal file
4
app/channels/application_cable/connection.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module ApplicationCable
|
||||
class Connection < ActionCable::Connection::Base
|
||||
end
|
||||
end
|
2
app/controllers/application_controller.rb
Normal file
2
app/controllers/application_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
end
|
5
app/controllers/books_controller.rb
Normal file
5
app/controllers/books_controller.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class BooksController < ApplicationController
|
||||
def index
|
||||
@books = Book.published.map { |book| BooksPresenter.new(book) }
|
||||
end
|
||||
end
|
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
2
app/helpers/application_helper.rb
Normal file
2
app/helpers/application_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module ApplicationHelper
|
||||
end
|
2
app/helpers/books_helper.rb
Normal file
2
app/helpers/books_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module BooksHelper
|
||||
end
|
6
app/javascript/channels/consumer.js
Normal file
6
app/javascript/channels/consumer.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Action Cable provides the framework to deal with WebSockets in Rails.
|
||||
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
|
||||
|
||||
import { createConsumer } from "@rails/actioncable"
|
||||
|
||||
export default createConsumer()
|
5
app/javascript/channels/index.js
Normal file
5
app/javascript/channels/index.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Load all the channels within this directory and all subdirectories.
|
||||
// Channel files must be named *_channel.js.
|
||||
|
||||
const channels = require.context('.', true, /_channel\.js$/)
|
||||
channels.keys().forEach(channels)
|
15
app/javascript/packs/application.js
Normal file
15
app/javascript/packs/application.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
// This file is automatically compiled by Webpack, along with any other files
|
||||
// present in this directory. You're encouraged to place your actual application logic in
|
||||
// a relevant structure within app/javascript and only use these pack files to reference
|
||||
// that code so it'll be compiled.
|
||||
|
||||
//= require materialize
|
||||
|
||||
import Rails from "@rails/ujs"
|
||||
import Turbolinks from "turbolinks"
|
||||
import * as ActiveStorage from "@rails/activestorage"
|
||||
import "channels"
|
||||
|
||||
Rails.start()
|
||||
Turbolinks.start()
|
||||
ActiveStorage.start()
|
7
app/jobs/application_job.rb
Normal file
7
app/jobs/application_job.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class ApplicationJob < ActiveJob::Base
|
||||
# Automatically retry jobs that encountered a deadlock
|
||||
# retry_on ActiveRecord::Deadlocked
|
||||
|
||||
# Most jobs are safe to ignore if the underlying records are no longer available
|
||||
# discard_on ActiveJob::DeserializationError
|
||||
end
|
4
app/mailers/application_mailer.rb
Normal file
4
app/mailers/application_mailer.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: 'from@example.com'
|
||||
layout 'mailer'
|
||||
end
|
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
2
app/models/author.rb
Normal file
2
app/models/author.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class Author < ApplicationRecord
|
||||
end
|
5
app/models/book.rb
Normal file
5
app/models/book.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class Book < ApplicationRecord
|
||||
has_and_belongs_to_many :authors
|
||||
|
||||
scope :published, -> { where(published: true) }
|
||||
end
|
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
11
app/presenters/books_presenter.rb
Normal file
11
app/presenters/books_presenter.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class BooksPresenter < SimpleDelegator
|
||||
include ActiveSupport::NumberHelper
|
||||
|
||||
def price
|
||||
number_to_currency(super / 100)
|
||||
end
|
||||
|
||||
def authors
|
||||
super.map { |author| "#{author.first_name} #{author.last_name}" }.join(', ')
|
||||
end
|
||||
end
|
17
app/views/books/index.html.erb
Normal file
17
app/views/books/index.html.erb
Normal file
|
@ -0,0 +1,17 @@
|
|||
<div class='container'>
|
||||
<% @books.each do |book| %>
|
||||
<div class='row'>
|
||||
<div class='col s4'>
|
||||
Title: <%= book.title %>
|
||||
</div>
|
||||
|
||||
<div class='col s4'>
|
||||
Price: <%= book.price %>
|
||||
</div>
|
||||
|
||||
<div class='col s4'>
|
||||
Authors: <%= book.authors %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
16
app/views/layouts/application.html.erb
Normal file
16
app/views/layouts/application.html.erb
Normal file
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Book store</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
||||
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
13
app/views/layouts/mailer.html.erb
Normal file
13
app/views/layouts/mailer.html.erb
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
/* Email styles need to be inline */
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
1
app/views/layouts/mailer.text.erb
Normal file
1
app/views/layouts/mailer.text.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= yield %>
|
Loading…
Add table
Add a link
Reference in a new issue