From ad80c40944743515a45d70014e8d5ffb88cd74fc Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 25 Jun 2017 00:00:28 -0400 Subject: Started designing index page --- .gitignore | 3 ++ Gemfile | 3 ++ Gemfile.lock | 7 ++++ app/assets/javascripts/entries.coffee | 3 ++ app/assets/javascripts/records.coffee | 3 ++ app/assets/stylesheets/application.css | 59 ++++++++++++++++++++++++++++ app/assets/stylesheets/entries.scss | 3 ++ app/assets/stylesheets/records.scss | 61 +++++++++++++++++++++++++++++ app/controllers/entries_controller.rb | 7 ++++ app/controllers/records_controller.rb | 7 ++++ app/helpers/entries_helper.rb | 2 + app/helpers/records_helper.rb | 2 + app/models/blog.rb | 4 ++ app/models/entry.rb | 9 +++++ app/models/record.rb | 5 +++ app/views/entries/show.html.haml | 2 + app/views/layouts/application.html.erb | 14 ------- app/views/layouts/application.html.haml | 14 +++++++ app/views/records/index.html.haml | 7 ++++ config/routes.rb | 7 ++++ db/migrate/20170624183854_create_records.rb | 10 +++++ db/migrate/20170625004938_create_entries.rb | 12 ++++++ db/schema.rb | 34 ++++++++++++++++ test/controllers/entries_controller_test.rb | 9 +++++ test/controllers/records_controller_test.rb | 9 +++++ test/fixtures/entries.yml | 15 +++++++ test/fixtures/links.yml | 9 +++++ test/fixtures/posts.yml | 9 +++++ test/fixtures/records.yml | 7 ++++ test/models/entry_test.rb | 7 ++++ test/models/link_test.rb | 7 ++++ test/models/post_test.rb | 7 ++++ test/models/record_test.rb | 7 ++++ 33 files changed, 350 insertions(+), 14 deletions(-) create mode 100644 app/assets/javascripts/entries.coffee create mode 100644 app/assets/javascripts/records.coffee create mode 100644 app/assets/stylesheets/entries.scss create mode 100644 app/assets/stylesheets/records.scss create mode 100644 app/controllers/entries_controller.rb create mode 100644 app/controllers/records_controller.rb create mode 100644 app/helpers/entries_helper.rb create mode 100644 app/helpers/records_helper.rb create mode 100644 app/models/blog.rb create mode 100644 app/models/entry.rb create mode 100644 app/models/record.rb create mode 100644 app/views/entries/show.html.haml delete mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/application.html.haml create mode 100644 app/views/records/index.html.haml create mode 100644 db/migrate/20170624183854_create_records.rb create mode 100644 db/migrate/20170625004938_create_entries.rb create mode 100644 db/schema.rb create mode 100644 test/controllers/entries_controller_test.rb create mode 100644 test/controllers/records_controller_test.rb create mode 100644 test/fixtures/entries.yml create mode 100644 test/fixtures/links.yml create mode 100644 test/fixtures/posts.yml create mode 100644 test/fixtures/records.yml create mode 100644 test/models/entry_test.rb create mode 100644 test/models/link_test.rb create mode 100644 test/models/post_test.rb create mode 100644 test/models/record_test.rb diff --git a/.gitignore b/.gitignore index dcc5b36..7511a24 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,8 @@ /node_modules /yarn-error.log +/tmux*.log +*.swp +tags .byebug_history diff --git a/Gemfile b/Gemfile index ed467b0..e2147ef 100644 --- a/Gemfile +++ b/Gemfile @@ -52,3 +52,6 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + +gem 'haml' +gem 'normalize-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 7b51875..60b7136 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,6 +66,9 @@ GEM ffi (1.9.18) globalid (0.4.0) activesupport (>= 4.2.0) + haml (5.0.1) + temple (>= 0.8.0) + tilt i18n (0.8.4) jbuilder (2.7.0) activesupport (>= 4.2.0) @@ -88,6 +91,7 @@ GEM nio4r (2.1.0) nokogiri (1.8.0) mini_portile2 (~> 2.2.0) + normalize-rails (4.1.1) public_suffix (2.0.5) puma (3.9.1) rack (2.0.3) @@ -145,6 +149,7 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) + temple (0.8.0) thor (0.19.4) thread_safe (0.3.6) tilt (2.0.7) @@ -173,8 +178,10 @@ DEPENDENCIES byebug capybara (~> 2.13) coffee-rails (~> 4.2) + haml jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) + normalize-rails puma (~> 3.7) rails (~> 5.1.1) sass-rails (~> 5.0) diff --git a/app/assets/javascripts/entries.coffee b/app/assets/javascripts/entries.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/entries.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/records.coffee b/app/assets/javascripts/records.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/records.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index d05ea0f..6fd12b7 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -10,6 +10,65 @@ * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * + *= require normalize-rails *= require_tree . *= require_self */ + +@import url('https://fonts.googleapis.com/css?family=Inconsolata'); + +body { + background-color: #bfefff; +} + +#container { + margin: 5em auto 0; + width: 50%; + border: 1px solid black; + background-color: white; + box-sizing: border-box; + -webkit-border-top-left-radius: 15px; + -webkit-border-top-right-radius: 15px; + -moz-border-radius-topleft: 15px; + -moz-border-radius-topright: 15px; + border-top-left-radius: 15px; + border-top-right-radius: 15px; +} + +#banner { + width: 100%; + border-bottom: 1px solid black; + padding: 1em; + box-sizing: border-box; +} + +#banner h1 { + text-align: center; + margin: 0; +} + +#banner h1 a { + text-decoration: none; + color: black; +} + +#banner h1 a:visited { + color: black; +} + +#main { + display: -webkit-flex; + display: flex; +} + +#content { + width: 75%; + box-sizing: border-box; + border-right: 1px solid black; +} + +#sidebar { + width: 25%; + box-sizing: border-box; + padding-right: 1em; +} diff --git a/app/assets/stylesheets/entries.scss b/app/assets/stylesheets/entries.scss new file mode 100644 index 0000000..f779b1b --- /dev/null +++ b/app/assets/stylesheets/entries.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Entries controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/records.scss b/app/assets/stylesheets/records.scss new file mode 100644 index 0000000..0054edd --- /dev/null +++ b/app/assets/stylesheets/records.scss @@ -0,0 +1,61 @@ +// Place all the styles related to the Records controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +#records { + padding: 0; + margin: 0 1em; + + & > li { + display: block; + padding: .25em 0; + + .description { + a { + text-decoration: none; + color: black; + font-family: 'Inconsolata', monospace; + + &:hover { + text-decoration: underline; + } + + &:visited { + color: black; + } + } + } + + .tags { + margin: .25em; + display: flex; + padding-left: 0; + + li { + display: inline; + font-size: .75em; + font-family: 'Inconsolata', monospace; + padding: .25em; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + + &.record-date { + background-color: #fef1bf; + } + + &.entry-type { + text-transform: uppercase; + + &.entry-type-blog { + background-color: #90fefb; + } + } + + & + li { + margin-left: 1em; + } + } + } + } +} diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb new file mode 100644 index 0000000..89d06c0 --- /dev/null +++ b/app/controllers/entries_controller.rb @@ -0,0 +1,7 @@ +class EntriesController < ApplicationController + + def show + @entry = Entry.where(directory: params[:directory], slug: params[:slug]).first + end + +end diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb new file mode 100644 index 0000000..200d63c --- /dev/null +++ b/app/controllers/records_controller.rb @@ -0,0 +1,7 @@ +class RecordsController < ApplicationController + + def index + @records = Record.order(created_at: :desc).limit(20) + end + +end diff --git a/app/helpers/entries_helper.rb b/app/helpers/entries_helper.rb new file mode 100644 index 0000000..ed8c595 --- /dev/null +++ b/app/helpers/entries_helper.rb @@ -0,0 +1,2 @@ +module EntriesHelper +end diff --git a/app/helpers/records_helper.rb b/app/helpers/records_helper.rb new file mode 100644 index 0000000..e63c599 --- /dev/null +++ b/app/helpers/records_helper.rb @@ -0,0 +1,2 @@ +module RecordsHelper +end diff --git a/app/models/blog.rb b/app/models/blog.rb new file mode 100644 index 0000000..d2b1c27 --- /dev/null +++ b/app/models/blog.rb @@ -0,0 +1,4 @@ +class Blog < Entry + validates :title, :body, presence: true +end + diff --git a/app/models/entry.rb b/app/models/entry.rb new file mode 100644 index 0000000..22b330a --- /dev/null +++ b/app/models/entry.rb @@ -0,0 +1,9 @@ +class Entry < ApplicationRecord + has_many :records, as: :recordable + + validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ + + def path + "/says/#{slug}" + end +end diff --git a/app/models/record.rb b/app/models/record.rb new file mode 100644 index 0000000..5837702 --- /dev/null +++ b/app/models/record.rb @@ -0,0 +1,5 @@ +class Record < ApplicationRecord + belongs_to :recordable, polymorphic: true + + validates :description, :recordable, presence: true +end diff --git a/app/views/entries/show.html.haml b/app/views/entries/show.html.haml new file mode 100644 index 0000000..8a2a2a9 --- /dev/null +++ b/app/views/entries/show.html.haml @@ -0,0 +1,2 @@ +

Entries#show

+

Find me in app/views/entries/show.html.erb

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index 732b30e..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - Thoughts - <%= csrf_meta_tags %> - - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - - - - <%= yield %> - - diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml new file mode 100644 index 0000000..ad1e8df --- /dev/null +++ b/app/views/layouts/application.html.haml @@ -0,0 +1,14 @@ +!!! 5 +%html + %head + %title Thoughts + = csrf_meta_tags + = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' + = javascript_include_tag 'application', 'data-turbolinks-track': 'reload' + %body + #container + #banner + %h1= link_to "Thoughts", root_url + #main + #content= yield + #sidebar I'm Fef. diff --git a/app/views/records/index.html.haml b/app/views/records/index.html.haml new file mode 100644 index 0000000..29c9dfb --- /dev/null +++ b/app/views/records/index.html.haml @@ -0,0 +1,7 @@ +%ul#records + - @records.each do |record| + %li + %span.description= link_to record.description, record.recordable.path + %ul.tags + %li.record-date= record.created_at.strftime("%m.%e.%y") + %li.entry-type{ class: "entry-type-#{record.recordable.type.downcase}" }= record.recordable.type diff --git a/config/routes.rb b/config/routes.rb index 787824f..64b02aa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,10 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + root "records#index" + + get 'says/:slug', to: 'entries#show' + + # get ':directory/:slug', to: 'entries#show', constraints: lambda { |request| + # Entry::DIRECTORIES.include? request.path_parameters['directory'] + # } end diff --git a/db/migrate/20170624183854_create_records.rb b/db/migrate/20170624183854_create_records.rb new file mode 100644 index 0000000..d407e15 --- /dev/null +++ b/db/migrate/20170624183854_create_records.rb @@ -0,0 +1,10 @@ +class CreateRecords < ActiveRecord::Migration[5.1] + def change + create_table :records do |t| + t.text :description + t.references :recordable, polymorphic: true, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20170625004938_create_entries.rb b/db/migrate/20170625004938_create_entries.rb new file mode 100644 index 0000000..0fb85b2 --- /dev/null +++ b/db/migrate/20170625004938_create_entries.rb @@ -0,0 +1,12 @@ +class CreateEntries < ActiveRecord::Migration[5.1] + def change + create_table :entries do |t| + t.string :title + t.text :body + t.string :slug, null: false + t.string :type, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..6eca6ad --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,34 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20170625004938) do + + create_table "entries", force: :cascade do |t| + t.string "title" + t.text "body" + t.string "directory", null: false + t.string "slug", null: false + t.string "type", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "records", force: :cascade do |t| + t.text "description" + t.string "recordable_type" + t.integer "recordable_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["recordable_type", "recordable_id"], name: "index_records_on_recordable_type_and_recordable_id" + end + +end diff --git a/test/controllers/entries_controller_test.rb b/test/controllers/entries_controller_test.rb new file mode 100644 index 0000000..6e2db59 --- /dev/null +++ b/test/controllers/entries_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class EntriesControllerTest < ActionDispatch::IntegrationTest + test "should get show" do + get entries_show_url + assert_response :success + end + +end diff --git a/test/controllers/records_controller_test.rb b/test/controllers/records_controller_test.rb new file mode 100644 index 0000000..6eeb2c3 --- /dev/null +++ b/test/controllers/records_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class RecordsControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get records_index_url + assert_response :success + end + +end diff --git a/test/fixtures/entries.yml b/test/fixtures/entries.yml new file mode 100644 index 0000000..7bb736a --- /dev/null +++ b/test/fixtures/entries.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + body: MyText + directory: MyString + slug: MyString + type: + +two: + title: MyString + body: MyText + directory: MyString + slug: MyString + type: diff --git a/test/fixtures/links.yml b/test/fixtures/links.yml new file mode 100644 index 0000000..1560785 --- /dev/null +++ b/test/fixtures/links.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + directory: MyString + slug: MyString + +two: + directory: MyString + slug: MyString diff --git a/test/fixtures/posts.yml b/test/fixtures/posts.yml new file mode 100644 index 0000000..e192dee --- /dev/null +++ b/test/fixtures/posts.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + title: MyString + body: MyText + +two: + title: MyString + body: MyText diff --git a/test/fixtures/records.yml b/test/fixtures/records.yml new file mode 100644 index 0000000..2e0c8cd --- /dev/null +++ b/test/fixtures/records.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + description: MyText + +two: + description: MyText diff --git a/test/models/entry_test.rb b/test/models/entry_test.rb new file mode 100644 index 0000000..d3293bc --- /dev/null +++ b/test/models/entry_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class EntryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/link_test.rb b/test/models/link_test.rb new file mode 100644 index 0000000..944bfce --- /dev/null +++ b/test/models/link_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class LinkTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/post_test.rb b/test/models/post_test.rb new file mode 100644 index 0000000..6d9d463 --- /dev/null +++ b/test/models/post_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/record_test.rb b/test/models/record_test.rb new file mode 100644 index 0000000..47cf779 --- /dev/null +++ b/test/models/record_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RecordTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end -- cgit 1.4.1