about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-07-03 13:58:57 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-07-03 14:01:41 -0400
commit8e15dbd73035c2a2198a2828a20ddcebe0739823 (patch)
treef93ada8d2c3c06e8cf1908bf5b0e22b1b54dd956 /app
parent49b11f2864f75bcfb8d0d01439939ed68aa90b8f (diff)
downloadthoughts-8e15dbd73035c2a2198a2828a20ddcebe0739823.tar.gz
thoughts-8e15dbd73035c2a2198a2828a20ddcebe0739823.tar.bz2
thoughts-8e15dbd73035c2a2198a2828a20ddcebe0739823.zip
Implemented streams
Currently there are no links to the pages for editing stream updates, and the admin panel for managing streams could probably have a better look & feel, but here's some basic working functionality.

refs #8
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/admin/layout.scss14
-rw-r--r--app/assets/stylesheets/main/entries.scss105
-rw-r--r--app/assets/stylesheets/main/records.scss4
-rw-r--r--app/controllers/admin/streams_controller.rb52
-rw-r--r--app/controllers/admin/updates_controller.rb52
-rw-r--r--app/controllers/streams_controller.rb7
-rw-r--r--app/helpers/streams_helper.rb2
-rw-r--r--app/models/stream.rb13
-rw-r--r--app/models/update.rb12
-rw-r--r--app/views/admin/blogs/edit.html.haml2
-rw-r--r--app/views/admin/blogs/new.html.haml2
-rw-r--r--app/views/admin/streams/_form.html.haml25
-rw-r--r--app/views/admin/streams/edit.html.haml2
-rw-r--r--app/views/admin/streams/index.html.haml13
-rw-r--r--app/views/admin/streams/new.html.haml2
-rw-r--r--app/views/admin/updates/_form.html.haml22
-rw-r--r--app/views/admin/updates/edit.html.haml2
-rw-r--r--app/views/admin/updates/new.html.haml2
-rw-r--r--app/views/blogs/_blog.html.haml2
-rw-r--r--app/views/layouts/admin.html.haml4
-rw-r--r--app/views/streams/_stream.html.haml6
-rw-r--r--app/views/streams/show.html.haml2
-rw-r--r--app/views/updates/_update.html.haml3
23 files changed, 310 insertions, 40 deletions
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index bbe5383..6645709 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss
@@ -80,7 +80,7 @@ body {
80 background-color: #eee; 80 background-color: #eee;
81} 81}
82 82
83#blog-form { 83#entry-form {
84 display: flex; 84 display: flex;
85 85
86 fieldset { 86 fieldset {
@@ -163,6 +163,18 @@ body {
163 td { 163 td {
164 padding: .25em; 164 padding: .25em;
165 } 165 }
166
167 .admin-actions {
168 margin: 0;
169
170 li {
171 display: inline;
172
173 &+li:before {
174 content: " - ";
175 }
176 }
177 }
166} 178}
167 179
168.details-module { 180.details-module {
diff --git a/app/assets/stylesheets/main/entries.scss b/app/assets/stylesheets/main/entries.scss index bd0b5ba..b2a07c5 100644 --- a/app/assets/stylesheets/main/entries.scss +++ b/app/assets/stylesheets/main/entries.scss
@@ -26,54 +26,87 @@
26 margin-bottom: 0; 26 margin-bottom: 0;
27 font-weight: normal; 27 font-weight: normal;
28 } 28 }
29}
29 30
30 #blog-content { 31#stream-post {
31 hyphens: auto; 32 h2 {
32 word-wrap: break-word; 33 background-color: #98FB98;
34 display: block;
35 font-size: 20px;
33 font-family: 'Roboto', sans-serif; 36 font-family: 'Roboto', sans-serif;
34 text-align: justify; 37 padding: 0.5em 20px;
38 border-top: 1px solid #7BCC70;
39 border-bottom: 1px solid #7BCC70;
40 }
35 41
36 a { 42 #stream-intro {
37 text-decoration: none; 43 font-size: 16px;
38 font-weight: bold; 44 margin: 0 20px;
45 }
39 46
40 &, &:visited { 47 .stream-update {
41 color: #ee2c2c; 48 font-size: 16px;
42 } 49 padding: 0 20px;
50 border-top: 1px solid #DEDEDE;
43 51
44 &:hover { 52 .update-posted {
45 text-decoration: underline; 53 display: block;
46 color: #9ea1ad; 54 font-style: italic;
47 } 55 text-align: right;
56 color: #989898;
57 font-size: 14px;
58 margin-top: .5em;
48 } 59 }
60 }
61}
62
63.entry-content {
64 hyphens: auto;
65 word-wrap: break-word;
66 text-align: justify;
67 font-family: 'Roboto', sans-serif;
68
69 a {
70 text-decoration: none;
71 font-weight: bold;
49 72
50 li { 73 &, &:visited {
51 & + li { 74 color: #ee2c2c;
52 margin-top: 1em;
53 }
54 } 75 }
55 76
56 img { 77 &:hover {
57 max-width: 100%; 78 text-decoration: underline;
58 box-sizing: border-box; 79 color: #9ea1ad;
59 } 80 }
81 }
60 82
61 figure { 83 li {
62 background-color: #eee; 84 & + li {
85 margin-top: 1em;
86 }
87 }
88
89 img {
90 max-width: 100%;
91 box-sizing: border-box;
92 }
93
94 figure {
95 background-color: #eee;
96 border: 1px solid #bbb;
97 padding: 0.25em 0.25em 0 0.25em;
98 font-size: 0.75em;
99 line-height: 24px;
100
101 img {
102 display: block;
63 border: 1px solid #bbb; 103 border: 1px solid #bbb;
64 padding: 0.25em 0.25em 0 0.25em; 104 }
65 font-size: 0.75em; 105
66 106 figcaption {
67 img { 107 font-style: italic;
68 display: block; 108 text-align: center;
69 border: 1px solid #bbb; 109 margin: 0.25em;
70 }
71
72 figcaption {
73 font-style: italic;
74 text-align: center;
75 margin: 0.25em;
76 }
77 } 110 }
78 } 111 }
79} 112}
diff --git a/app/assets/stylesheets/main/records.scss b/app/assets/stylesheets/main/records.scss index dd4eac1..f57dded 100644 --- a/app/assets/stylesheets/main/records.scss +++ b/app/assets/stylesheets/main/records.scss
@@ -52,6 +52,10 @@
52 &.entry-type-blog { 52 &.entry-type-blog {
53 background-color: #90fefb; 53 background-color: #90fefb;
54 } 54 }
55
56 &.entry-type-stream, &.entry-type-update {
57 background-color: #98FB98;
58 }
55 } 59 }
56 60
57 & + li { 61 & + li {
diff --git a/app/controllers/admin/streams_controller.rb b/app/controllers/admin/streams_controller.rb new file mode 100644 index 0000000..86dec06 --- /dev/null +++ b/app/controllers/admin/streams_controller.rb
@@ -0,0 +1,52 @@
1class Admin::StreamsController < Admin::AdminController
2 before_action :set_section
3
4 def index
5 @streams = Stream.order(created_at: :desc)
6 end
7
8 def new
9 @stream = Stream.new
10 end
11
12 def create
13 @stream = Stream.new(stream_params)
14
15 if @stream.save
16 flash.notice = "Stream created successfully!"
17
18 render :edit
19 else
20 flash.alert = "Error creating stream."
21
22 render :new
23 end
24 end
25
26 def edit
27 @stream = Stream.find(params[:id])
28 end
29
30 def update
31 @stream = Stream.find(params[:id])
32
33 if @stream.update_attributes(stream_params)
34 flash.notice = "Stream updated successfully!"
35 else
36 flash.alert = "Error updating stream."
37 end
38
39 render :edit
40 end
41
42 private
43
44 def stream_params
45 params.require(:stream).permit(:title, :body, :slug, records_attributes: [:description, :_destroy])
46 end
47
48 def set_section
49 @section = "streams"
50 end
51
52end
diff --git a/app/controllers/admin/updates_controller.rb b/app/controllers/admin/updates_controller.rb new file mode 100644 index 0000000..9bf9caf --- /dev/null +++ b/app/controllers/admin/updates_controller.rb
@@ -0,0 +1,52 @@
1class Admin::UpdatesController < Admin::AdminController
2 before_action :set_section
3
4 def new
5 @stream = Stream.find(params[:stream_id])
6 @update = @stream.updates.build
7 end
8
9 def create
10 @stream = Stream.find(params[:stream_id])
11 @update = @stream.updates.build(update_params)
12
13 if @update.save
14 flash.notice = "Update created successfully!"
15
16 render :edit
17 else
18 flash.alert = "Error creating update."
19
20 render :new
21 end
22 end
23
24 def edit
25 @stream = Stream.find(params[:stream_id])
26 @update = Update.find(params[:id])
27 end
28
29 def update
30 @stream = Stream.find(params[:stream_id])
31 @update = Update.find(params[:id])
32
33 if @update.update_attributes(update_params)
34 flash.notice = "Update updated successfully!"
35 else
36 flash.alert = "Error updating update."
37 end
38
39 render :edit
40 end
41
42 private
43
44 def update_params
45 params.require(:update).permit(:body, records_attributes: [:description, :_destroy])
46 end
47
48 def set_section
49 @section = "streams"
50 end
51
52end
diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb new file mode 100644 index 0000000..664f533 --- /dev/null +++ b/app/controllers/streams_controller.rb
@@ -0,0 +1,7 @@
1class StreamsController < ApplicationController
2
3 def show
4 @stream = Stream.find_by_slug(params[:slug])
5 end
6
7end
diff --git a/app/helpers/streams_helper.rb b/app/helpers/streams_helper.rb new file mode 100644 index 0000000..ad2665b --- /dev/null +++ b/app/helpers/streams_helper.rb
@@ -0,0 +1,2 @@
1module StreamsHelper
2end
diff --git a/app/models/stream.rb b/app/models/stream.rb new file mode 100644 index 0000000..7faa370 --- /dev/null +++ b/app/models/stream.rb
@@ -0,0 +1,13 @@
1class Stream < ApplicationRecord
2 has_many :records, as: :recordable, inverse_of: :recordable
3 has_many :updates
4
5 validates :title, presence: true
6 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/
7
8 accepts_nested_attributes_for :records, allow_destroy: true
9
10 def path
11 "/thinks/#{slug}"
12 end
13end
diff --git a/app/models/update.rb b/app/models/update.rb new file mode 100644 index 0000000..41cc453 --- /dev/null +++ b/app/models/update.rb
@@ -0,0 +1,12 @@
1class Update < ApplicationRecord
2 has_many :records, as: :recordable, inverse_of: :recordable
3 belongs_to :stream
4
5 validates :stream, :body, presence: true
6
7 accepts_nested_attributes_for :records, allow_destroy: true
8
9 def path
10 "/thinks/#{stream.slug}\#update-#{id}"
11 end
12end
diff --git a/app/views/admin/blogs/edit.html.haml b/app/views/admin/blogs/edit.html.haml index 3f4d412..f356069 100644 --- a/app/views/admin/blogs/edit.html.haml +++ b/app/views/admin/blogs/edit.html.haml
@@ -1,2 +1,2 @@
1= form_for @blog, url: admin_blog_url(@blog), html: { id: "blog-form" } do |f| 1= form_for @blog, url: admin_blog_url(@blog), html: { id: "entry-form" } do |f|
2 = render partial: "form", locals: { f: f } 2 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/blogs/new.html.haml b/app/views/admin/blogs/new.html.haml index 914f27b..0005278 100644 --- a/app/views/admin/blogs/new.html.haml +++ b/app/views/admin/blogs/new.html.haml
@@ -1,2 +1,2 @@
1= form_for @blog, url: admin_blogs_url, html: { id: "blog-form" } do |f| 1= form_for @blog, url: admin_blogs_url, html: { id: "entry-form" } do |f|
2 = render partial: "form", locals: { f: f } 2 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/streams/_form.html.haml b/app/views/admin/streams/_form.html.haml new file mode 100644 index 0000000..ce457cb --- /dev/null +++ b/app/views/admin/streams/_form.html.haml
@@ -0,0 +1,25 @@
1%fieldset#content
2 .title-field
3 = f.label :title
4 = f.text_field :title, placeholder: "Title"
5 .slug-field
6 = f.label :slug, "https://feffernoo.se/thinks/"
7 = f.text_field :slug, placeholder: "insert-slug-here"
8 .body-field
9 = f.label :body
10 = f.cktext_area :body
11%fieldset#details
12 - if f.object.errors.any?
13 #errors.details-module
14 %h3 Error!
15 %ul
16 - f.object.errors.full_messages.each do |error|
17 %li= error
18 .details-module
19 = f.fields_for :records, Record.new do |builder|
20 .should-create-record-field
21 = builder.check_box :_destroy, {checked: false}, "0", "1"
22 = builder.label :_destroy, "Create record?"
23 .record-description-field
24 = builder.text_area :description, placeholder: "record text"
25 .details-module= f.submit
diff --git a/app/views/admin/streams/edit.html.haml b/app/views/admin/streams/edit.html.haml new file mode 100644 index 0000000..1b58331 --- /dev/null +++ b/app/views/admin/streams/edit.html.haml
@@ -0,0 +1,2 @@
1= form_for @stream, url: admin_stream_url(@stream), html: { id: "entry-form" } do |f|
2 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/streams/index.html.haml b/app/views/admin/streams/index.html.haml new file mode 100644 index 0000000..c69c6f9 --- /dev/null +++ b/app/views/admin/streams/index.html.haml
@@ -0,0 +1,13 @@
1%table#entries
2 %tr
3 %th Title
4 %th Date created
5 %th
6 - @streams.each do |stream|
7 %tr{ class: cycle("even", "odd") }
8 %td= stream.title
9 %td= stream.created_at.strftime("%B %d, %Y, %l:%M%P")
10 %td
11 %ul.admin-actions
12 %li= link_to "Edit", edit_admin_stream_url(stream)
13 %li= link_to "Add Update", new_admin_stream_update_url(stream)
diff --git a/app/views/admin/streams/new.html.haml b/app/views/admin/streams/new.html.haml new file mode 100644 index 0000000..52febf5 --- /dev/null +++ b/app/views/admin/streams/new.html.haml
@@ -0,0 +1,2 @@
1= form_for @stream, url: admin_streams_url, html: { id: "entry-form" } do |f|
2 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/updates/_form.html.haml b/app/views/admin/updates/_form.html.haml new file mode 100644 index 0000000..9dd8741 --- /dev/null +++ b/app/views/admin/updates/_form.html.haml
@@ -0,0 +1,22 @@
1%fieldset#content
2 .title-field
3 = f.label :title
4 = f.text_field :title, value: @stream.title, readonly: true
5 .body-field
6 = f.label :body
7 = f.cktext_area :body
8%fieldset#details
9 - if f.object.errors.any?
10 #errors.details-module
11 %h3 Error!
12 %ul
13 - f.object.errors.full_messages.each do |error|
14 %li= error
15 .details-module
16 = f.fields_for :records, Record.new do |builder|
17 .should-create-record-field
18 = builder.check_box :_destroy, {checked: false}, "0", "1"
19 = builder.label :_destroy, "Create record?"
20 .record-description-field
21 = builder.text_area :description, placeholder: "record text"
22 .details-module= f.submit
diff --git a/app/views/admin/updates/edit.html.haml b/app/views/admin/updates/edit.html.haml new file mode 100644 index 0000000..5651d23 --- /dev/null +++ b/app/views/admin/updates/edit.html.haml
@@ -0,0 +1,2 @@
1= form_for @update, url: admin_stream_update_url(@stream, @update), html: { id: "entry-form" } do |f|
2 = render partial: "form", locals: { f: f }
diff --git a/app/views/admin/updates/new.html.haml b/app/views/admin/updates/new.html.haml new file mode 100644 index 0000000..14c6d77 --- /dev/null +++ b/app/views/admin/updates/new.html.haml
@@ -0,0 +1,2 @@
1= form_for @update, url: admin_stream_updates_url(@stream), html: { id: "entry-form" } do |f|
2 = render partial: "form", locals: { f: f }
diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index e83d21a..91b1d20 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml
@@ -1,3 +1,3 @@
1%article#blog-post 1%article#blog-post
2 %h2#blog-title= blog.title 2 %h2#blog-title= blog.title
3 %section#blog-content= blog.body.html_safe 3 %section#blog-content.entry-content= blog.body.html_safe
diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 7f8c171..68bbd96 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml
@@ -24,5 +24,9 @@
24 = link_to "Blogs", admin_blogs_url, class: "major-link" 24 = link_to "Blogs", admin_blogs_url, class: "major-link"
25 %ul.minors 25 %ul.minors
26 %li.minor= link_to "New blog", new_admin_blog_url 26 %li.minor= link_to "New blog", new_admin_blog_url
27 %li{major_sidebar_attrs("streams")}
28 = link_to "Streams", admin_streams_url, class: "major-link"
29 %ul.minors
30 %li.minor= link_to "New stream", new_admin_stream_url
27 #main 31 #main
28 = yield 32 = yield
diff --git a/app/views/streams/_stream.html.haml b/app/views/streams/_stream.html.haml new file mode 100644 index 0000000..84a6478 --- /dev/null +++ b/app/views/streams/_stream.html.haml
@@ -0,0 +1,6 @@
1%article#stream-post
2 %h2#stream-title= stream.title
3 - unless stream.body.blank?
4 %header#stream-intro.entry-content= stream.body.html_safe
5 - unless stream.updates.empty?
6 = render stream.updates
diff --git a/app/views/streams/show.html.haml b/app/views/streams/show.html.haml new file mode 100644 index 0000000..dcec0a2 --- /dev/null +++ b/app/views/streams/show.html.haml
@@ -0,0 +1,2 @@
1.breadcrumb= link_to "← Back to home page", root_path
2= render @stream
diff --git a/app/views/updates/_update.html.haml b/app/views/updates/_update.html.haml new file mode 100644 index 0000000..c8ce224 --- /dev/null +++ b/app/views/updates/_update.html.haml
@@ -0,0 +1,3 @@
1%section.stream-update.entry-content{ id: "update-#{update.id}" }
2 %time.update-posted= update.created_at.strftime("%b #{update.created_at.day.ordinalize} %Y at %-I:%M:%S%P")
3 = update.body.html_safe