lines-engine 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/lines/admin/application_controller.rb +7 -5
- data/app/controllers/lines/admin/articles_controller.rb +131 -129
- data/app/controllers/lines/admin/authors_controller.rb +50 -49
- data/app/controllers/lines/admin/pictures_controller.rb +28 -27
- data/lib/lines/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efaf76786e0d64f0b0c688a19d7b05cefa2ed5a6
|
4
|
+
data.tar.gz: c665412cae4d55a0091bb5d097b792c1514b9afd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b6d6e8e98c1d9291cae3c43cc78a5b80c453f04db14b8c1f44c0f9ff7478530e4abb580b4202ba34d3fbbf0ded655cb8c5d19301c8c24b3643d6ae8d399f8aa
|
7
|
+
data.tar.gz: 15feb2f96d2d9a6a897e7cca3c243236360902c3f2ee7e9cb88d0d226aecd11f2ed8bbc486e75318cf77608f58afe4bb5bcfe5ce86dc6d66f9e9c37eb915f8ad
|
data/Gemfile.lock
CHANGED
@@ -6,14 +6,16 @@
|
|
6
6
|
require_dependency "lines/application_controller"
|
7
7
|
|
8
8
|
module Lines
|
9
|
+
module Admin
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
class ApplicationController < Lines::ApplicationController
|
12
|
+
protect_from_forgery
|
12
13
|
|
13
|
-
|
14
|
+
before_action :authorize
|
14
15
|
|
15
|
-
|
16
|
+
layout 'lines/admin'
|
16
17
|
|
18
|
+
end
|
19
|
+
|
17
20
|
end
|
18
|
-
|
19
21
|
end
|
@@ -7,166 +7,168 @@
|
|
7
7
|
require_dependency "lines/admin/application_controller"
|
8
8
|
|
9
9
|
module Lines
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
module Admin
|
11
|
+
|
12
|
+
class ArticlesController < ApplicationController
|
13
|
+
|
14
|
+
autocomplete :tag, :name, class_name: 'ActsAsTaggableOn::Tag'
|
15
|
+
before_action :process_base64_upload, only: [:create, :update]
|
16
|
+
|
17
|
+
# Lists all articles. Provides <tt>@articles_unpublished</tt> and
|
18
|
+
# <tt>@articles_published</tt> to distinguish between published and
|
19
|
+
# unpublished articles
|
20
|
+
def index
|
21
|
+
@articles = Article.order('published ASC, featured DESC, published_at DESC').page(params[:page]).per(25)
|
22
|
+
@articles_unpublished = @articles.select{|a| a.published == false}
|
23
|
+
@articles_published = @articles.select{|a| a.published == true}
|
24
|
+
respond_to do |format|
|
25
|
+
format.html # index.html.erb
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# GET /admin/articles/1
|
30
|
+
def show
|
31
|
+
@article = Article.find(params[:id])
|
32
|
+
@first_page = true
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
respond_to do |format|
|
35
|
+
format.html {render :show, layout: 'lines/preview'}
|
36
|
+
end
|
35
37
|
end
|
36
|
-
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
# GET /admin/articles/new
|
40
|
+
def new
|
41
|
+
@article = Lines::Article.new
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
respond_to do |format|
|
44
|
+
format.html # new.html.erb
|
45
|
+
end
|
44
46
|
end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
# GET /admin/articles/1/edit
|
49
|
+
def edit
|
50
|
+
@article = Article.find(params[:id])
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
# POST /admin/articles
|
54
|
+
def create
|
55
|
+
@article = Article.new(article_params)
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
respond_to do |format|
|
58
|
+
if @article.save
|
59
|
+
format.html { redirect_to admin_article_path(@article), notice: 'Article was successfully created.' }
|
60
|
+
else
|
61
|
+
format.html { render action: "new" }
|
62
|
+
end
|
61
63
|
end
|
62
64
|
end
|
63
|
-
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
# PUT /admin/articles/1
|
67
|
+
# TODO: Very much is happening here. Move deletion of hero_image to the article model
|
68
|
+
def update
|
69
|
+
@article = Article.find(params[:id])
|
70
|
+
a_params = article_params
|
70
71
|
|
71
|
-
|
72
|
-
|
72
|
+
# replace picture_path with the new uploaded file
|
73
|
+
a_params[:hero_image] = @uploaded_file if @uploaded_file
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
# delete uploaded hero image when predifined image is selected
|
76
|
+
if !a_params[:hero_image_cache].present? && a_params[:short_hero_image].present?
|
77
|
+
@article.remove_hero_image!
|
78
|
+
@article.remove_hero_image = true
|
79
|
+
@article.save
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
respond_to do |format|
|
83
|
+
if @article.update_attributes(article_params)
|
84
|
+
ActionController::Base.new.expire_fragment(@article)
|
85
|
+
format.html { redirect_to admin_article_path(@article), notice: 'Article was successfully updated.' }
|
86
|
+
else
|
87
|
+
format.html { render action: "edit" }
|
88
|
+
end
|
87
89
|
end
|
88
90
|
end
|
89
|
-
end
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
# DELETE /admin/articles/1
|
93
|
+
def destroy
|
94
|
+
@article = Article.find(params[:id])
|
95
|
+
@article.destroy
|
95
96
|
|
96
|
-
|
97
|
-
|
97
|
+
respond_to do |format|
|
98
|
+
format.html { redirect_to admin_articles_url }
|
99
|
+
end
|
98
100
|
end
|
99
|
-
end
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
# Toggles published state of an article
|
103
|
+
def toggle_publish
|
104
|
+
@article = Article.find(params[:article_id])
|
105
|
+
@article.update_attributes(published: !@article.published)
|
106
|
+
redirect_to admin_articles_url, notice: 'Article updated!'
|
107
|
+
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
109
|
+
# Toggles featured state of an article
|
110
|
+
def toggle_feature
|
111
|
+
@article = Article.find(params[:article_id])
|
112
|
+
old_featured = Article.where(featured: true)
|
113
|
+
if old_featured.size > 0
|
114
|
+
old_featured.each do |article|
|
115
|
+
article.update_attributes(featured: false)
|
116
|
+
end
|
115
117
|
end
|
118
|
+
@article.update_attributes(featured: !@article.featured)
|
119
|
+
redirect_to admin_articles_url, notice: 'Article updated!'
|
116
120
|
end
|
117
|
-
@article.update_attributes(featured: !@article.featured)
|
118
|
-
redirect_to admin_articles_url, notice: 'Article updated!'
|
119
|
-
end
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
122
|
+
# Handles base64 encoded file uploads
|
123
|
+
def process_base64_upload
|
124
|
+
@uploaded_file = nil
|
125
|
+
#check if file is given
|
126
|
+
if params[:article][:hero_image_file] != ""
|
127
|
+
|
128
|
+
picture_filename = "hero_image"
|
129
|
+
picture_original_filename = "hero_image"
|
130
|
+
picture_content_type = splitBase64(params[:article][:hero_image_file])[:type]
|
131
|
+
picture_data = splitBase64(params[:article][:hero_image_file])[:data]
|
132
|
+
|
133
|
+
#create a new tempfile named fileupload
|
134
|
+
tempfile = Tempfile.new("fileupload")
|
135
|
+
tempfile.binmode
|
136
|
+
|
137
|
+
#get the file and decode it with base64 then write it to the tempfile
|
138
|
+
tempfile.write(Base64.decode64(picture_data))
|
139
|
+
|
140
|
+
#create a new uploaded file
|
141
|
+
@uploaded_file = ActionDispatch::Http::UploadedFile.new(
|
142
|
+
tempfile: tempfile,
|
143
|
+
filename: picture_filename,
|
144
|
+
original_filename: picture_original_filename
|
145
|
+
)
|
146
|
+
@uploaded_file.content_type = picture_content_type
|
147
|
+
end
|
146
148
|
end
|
147
|
-
end
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
def splitBase64(uri)
|
151
|
+
if uri.match(%r{^data:(.*?);(.*?),(.*)$})
|
152
|
+
return {
|
153
|
+
type: $1, # "image/png"
|
154
|
+
encoder: $2, # "base64"
|
155
|
+
data: $3, # data string
|
156
|
+
extension: $1.split('/')[1] # "png"
|
157
|
+
}
|
158
|
+
end
|
157
159
|
end
|
158
|
-
end
|
159
160
|
|
160
|
-
|
161
|
+
private
|
161
162
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
163
|
+
# Allowed attribute with strong_params
|
164
|
+
def article_params
|
165
|
+
params.require(:article).permit(:content, :hero_image, :short_hero_image, :published, :published_at,
|
166
|
+
:sub_title, :title, :pictures, :author_ids, :hero_image_cache, :tag_list, :gplus_url, :featured,
|
167
|
+
:document, :document_cache, :hero_image_file, :remove_document, :pictures, :authors,
|
168
|
+
pictures_attributes: [:id, :image, :name, :article_id], author_ids: [] )
|
169
|
+
end
|
169
170
|
|
170
|
-
|
171
|
+
end
|
171
172
|
|
173
|
+
end
|
172
174
|
end
|
@@ -3,68 +3,69 @@
|
|
3
3
|
require_dependency "lines/admin/application_controller"
|
4
4
|
|
5
5
|
module Lines
|
6
|
+
module Admin
|
7
|
+
class AuthorsController < ApplicationController
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@authors = Author.all
|
12
|
-
end
|
9
|
+
# Listes all authroes
|
10
|
+
def index
|
11
|
+
@authors = Author.all
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
# Shows an author
|
15
|
+
def show
|
16
|
+
@author = Author.find(params[:id])
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
# New author
|
20
|
+
def new
|
21
|
+
@author = Lines::Author.new
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
# Edit an existing author
|
25
|
+
def edit
|
26
|
+
@author = Author.find(params[:id])
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# Create a new author from params
|
30
|
+
def create
|
31
|
+
@author = Author.new(author_params)
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
if @author.save
|
34
|
+
redirect_to admin_author_path @author, notice: 'Author was successfully created.'
|
35
|
+
else
|
36
|
+
render action: "new"
|
37
|
+
end
|
37
38
|
end
|
38
|
-
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
# Update an existing author from params
|
41
|
+
def update
|
42
|
+
@author = Author.find(params[:id])
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
if @author.update_attributes(params[:author])
|
45
|
+
redirect_to admin_author_path @author, notice: 'Author was successfully updated.'
|
46
|
+
else
|
47
|
+
render action: "edit"
|
48
|
+
end
|
48
49
|
end
|
49
|
-
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
# Delete an author
|
52
|
+
def destroy
|
53
|
+
@author = Author.find(params[:id])
|
54
|
+
if @author.destroy
|
55
|
+
redirect_to admin_authors_url
|
56
|
+
else
|
57
|
+
@authors = Author.all
|
58
|
+
render "index"
|
59
|
+
end
|
59
60
|
end
|
60
|
-
end
|
61
61
|
|
62
|
-
|
62
|
+
private
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
# Use strong_params
|
65
|
+
def author_params
|
66
|
+
params.require(:author).permit(:email, :name, :description, :gplus_profile)
|
67
|
+
end
|
68
|
+
end
|
69
69
|
|
70
|
+
end
|
70
71
|
end
|
@@ -2,42 +2,43 @@
|
|
2
2
|
require_dependency "lines/admin/application_controller"
|
3
3
|
|
4
4
|
module Lines
|
5
|
+
module Admin
|
5
6
|
|
7
|
+
class PicturesController < ApplicationController
|
8
|
+
def create
|
9
|
+
@picture = Picture.create(picture_params)
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
# PUT /admin/pictures/1
|
13
|
-
def update
|
14
|
-
@picture = Picture.find(params[:id])
|
12
|
+
# PUT /admin/pictures/1
|
13
|
+
def update
|
14
|
+
@picture = Picture.find(params[:id])
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
respond_to do |format|
|
17
|
+
if @picture.update_attributes(picture_params[:picture])
|
18
|
+
format.html { redirect_to @picture, notice: 'Picture was successfully updated.' }
|
19
|
+
else
|
20
|
+
format.html { render action: "edit" }
|
21
|
+
end
|
21
22
|
end
|
22
23
|
end
|
23
|
-
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# Deletes a picture. Only responds to JS requests.
|
26
|
+
def destroy
|
27
|
+
@picture = Picture.find(params[:id])
|
28
|
+
@picture.destroy
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
respond_to do |format|
|
31
|
+
format.js
|
32
|
+
end
|
32
33
|
end
|
33
|
-
end
|
34
34
|
|
35
|
-
|
35
|
+
private
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
# strong_params
|
38
|
+
def picture_params
|
39
|
+
params.fetch(:picture, {}).permit(:image)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
41
43
|
end
|
42
|
-
|
43
44
|
end
|
data/lib/lines/version.rb
CHANGED