days 0.0.1.earlier → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/README.md +2 -0
- data/app/images/glyphicons-halflings-white.png +0 -0
- data/app/images/glyphicons-halflings.png +0 -0
- data/app/javascripts/bootstrap.js +2159 -0
- data/app/javascripts/bootstrap.min.js +6 -0
- data/app/javascripts/jquery-1.8.3.min.js +2 -0
- data/app/stylesheets/admin/login.scss +26 -0
- data/app/stylesheets/admin.scss +28 -0
- data/app/stylesheets/bootstrap-responsive.css +1092 -0
- data/app/stylesheets/bootstrap-responsive.min.css +9 -0
- data/app/stylesheets/bootstrap.css +6039 -0
- data/app/stylesheets/bootstrap.min.css +9 -0
- data/app/stylesheets/style.scss +132 -0
- data/app/views/admin/categories.haml +53 -0
- data/app/views/admin/entries/form.haml +55 -0
- data/app/views/admin/entries/index.haml +31 -0
- data/app/views/admin/index.haml +0 -0
- data/app/views/admin/login.haml +19 -0
- data/app/views/admin/setup.haml +22 -0
- data/app/views/admin/users/form.haml +25 -0
- data/app/views/admin/users/index.haml +23 -0
- data/app/views/admin.haml +37 -0
- data/app/views/entries.haml +4 -0
- data/app/views/entry.haml +32 -0
- data/app/views/layout.haml +32 -0
- data/bin/days +5 -0
- data/bootstrap.sh +41 -0
- data/days.gemspec +25 -2
- data/lib/days/app/admin/categories.rb +43 -0
- data/lib/days/app/admin/entries.rb +72 -0
- data/lib/days/app/admin/session.rb +28 -0
- data/lib/days/app/admin/setup.rb +20 -0
- data/lib/days/app/admin/users.rb +59 -0
- data/lib/days/app/admin.rb +11 -0
- data/lib/days/app/entries.rb +84 -0
- data/lib/days/app.rb +110 -0
- data/lib/days/command.rb +158 -0
- data/lib/days/config.rb +42 -0
- data/lib/days/helpers.rb +101 -0
- data/lib/days/migrate/20121221000000_create_entries.rb +18 -0
- data/lib/days/migrate/20121221001000_create_users.rb +12 -0
- data/lib/days/migrate/20121221002000_create_categories.rb +17 -0
- data/lib/days/migrator.rb +33 -0
- data/lib/days/models/category.rb +12 -0
- data/lib/days/models/entry.rb +63 -0
- data/lib/days/models/user.rb +14 -0
- data/lib/days/models.rb +7 -0
- data/lib/days/version.rb +1 -1
- data/lib/days.rb +3 -1
- data/scripts/lokka_export.rb +45 -0
- data/skeleton/days/Gemfile +11 -0
- data/skeleton/days/config.ru +6 -0
- data/skeleton/days/config.yml +33 -0
- data/skeleton/days/db/.gitkeep +0 -0
- data/spec/controllers/admin/categories_spec.rb +100 -0
- data/spec/controllers/admin/entries_spec.rb +185 -0
- data/spec/controllers/admin/session_spec.rb +112 -0
- data/spec/controllers/admin/setup_spec.rb +85 -0
- data/spec/controllers/admin/users_spec.rb +163 -0
- data/spec/controllers/entries_spec.rb +129 -0
- data/spec/environment/Gemfile +11 -0
- data/spec/environment/config.ru +6 -0
- data/spec/environment/config.yml +32 -0
- data/spec/environment/db/.gitkeep +0 -0
- data/spec/fixtures/categories.yml +5 -0
- data/spec/fixtures/entries.yml +25 -0
- data/spec/fixtures/users.yml +6 -0
- data/spec/helpers_spec.rb +117 -0
- data/spec/models/entry_spec.rb +238 -0
- data/spec/shared/admin.rb +8 -0
- data/spec/spec_helper.rb +134 -0
- data/tasks +9 -0
- metadata +353 -9
@@ -0,0 +1,37 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{charset: 'UTF-8'}
|
5
|
+
%meta{name: "viewport", content: "width=device-width, initial-scale=1.0"}
|
6
|
+
%link{href: "/assets/bootstrap.min.css", rel: "stylesheet"}
|
7
|
+
%link{href: "/assets/admin.css", rel: "stylesheet", media: "screen"}
|
8
|
+
%link{href: "/assets/bootstrap-responsive.min.css", rel: "stylesheet"}
|
9
|
+
%script{src: '/assets/jquery-1.8.3.min.js'}
|
10
|
+
%script{src: '/assets/bootstrap.min.js'}
|
11
|
+
- if @title
|
12
|
+
%title #{@title} - Days Admin
|
13
|
+
- else
|
14
|
+
%title Days Admin
|
15
|
+
%body
|
16
|
+
.navbar.navbar-inverse.navbar-fixed-top
|
17
|
+
.navbar-inner
|
18
|
+
.container
|
19
|
+
%a.btn.btn-navbar{data: {toggle: 'collapse', target: '.nav-collapse'}}
|
20
|
+
%span.icon-bar
|
21
|
+
%span.icon-bar
|
22
|
+
%span.icon-bar
|
23
|
+
%a.brand{href: '/admin/'} Days
|
24
|
+
%form.navbar-form.pull-right{action: "/admin/logout", method: "POST"}
|
25
|
+
!= csrf_tag
|
26
|
+
%button.btn.btn-link{type: 'submit'} Log out
|
27
|
+
%a.btn.btn-primary{href: '/admin/entries/new'} New Entry
|
28
|
+
|
29
|
+
%div.nav-collapse.collapse
|
30
|
+
%ul.nav
|
31
|
+
%li
|
32
|
+
%a{href: '/admin/entries'} Entries
|
33
|
+
%li
|
34
|
+
%a{href: '/admin/categories'} Categories
|
35
|
+
%li
|
36
|
+
%a{href: '/admin/users'} Users
|
37
|
+
!= yield
|
@@ -0,0 +1,32 @@
|
|
1
|
+
- full ||= false
|
2
|
+
%article.entry
|
3
|
+
.left
|
4
|
+
%span.date= entry.published_at.strftime("%Y-%m-%d")
|
5
|
+
!= haml :entry_left, locals: {entry: entry} rescue ''
|
6
|
+
.right
|
7
|
+
%header
|
8
|
+
%h1
|
9
|
+
%a{href: entry_path(entry)}= entry.title
|
10
|
+
.categories
|
11
|
+
- entry.categories.each do |category|
|
12
|
+
%span.category
|
13
|
+
%a{href: "/category/#{category.name}"}>= category.name
|
14
|
+
|
15
|
+
!= haml :entry_header, locals: {entry: entry} rescue ''
|
16
|
+
%section
|
17
|
+
- if full
|
18
|
+
!= entry.rendered.gsub(/<!-- *more *-->/,'<a name="more"></a>')
|
19
|
+
- else
|
20
|
+
!= entry.short_rendered { "... <a href=\"#{entry_path(entry)}#more\">Continue Reading...</a>"}
|
21
|
+
|
22
|
+
%footer
|
23
|
+
Published at
|
24
|
+
%date #{entry.published_at}
|
25
|
+
|
|
26
|
+
%a{href: entry_path(entry)} Permalink
|
27
|
+
- if logged_in?
|
28
|
+
|
|
29
|
+
%a{href: "/admin/entries/#{entry.id}"} Edit
|
30
|
+
|
31
|
+
!= haml :entry_footer, locals: {entry: entry} rescue ''
|
32
|
+
.clear
|
@@ -0,0 +1,32 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%meta{charset: 'UTF-8'}
|
5
|
+
%link{rel: 'stylesheet', type: 'text/css', href: '/assets/style.css'}
|
6
|
+
%link{rel: "alternate", type: "application/atom+xml", href: '/feed', title: 'Feed'}
|
7
|
+
!= haml :head rescue ''
|
8
|
+
- if @title
|
9
|
+
%title #{@title} - #{config.title}
|
10
|
+
- else
|
11
|
+
%title= config.title
|
12
|
+
%body
|
13
|
+
.container
|
14
|
+
%header#header
|
15
|
+
%h1
|
16
|
+
%a{href: '/'}= config.title
|
17
|
+
!= yield
|
18
|
+
%footer#footer
|
19
|
+
%section
|
20
|
+
%nav
|
21
|
+
%h3 Categories
|
22
|
+
%ul
|
23
|
+
- Days::Category.all.each do |category|
|
24
|
+
%li
|
25
|
+
%a{href: "/category/#{URI.encode_www_form_component(category.name)}"}= category.name
|
26
|
+
%section
|
27
|
+
%h3 Recent Entries
|
28
|
+
%ul
|
29
|
+
- Days::Entry.published.first(10).each do |entry|
|
30
|
+
%li
|
31
|
+
%a{href: entry_path(entry)}= entry.title
|
32
|
+
|
data/bin/days
ADDED
data/bootstrap.sh
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
if [ "$1" = "" ]; then
|
4
|
+
to="sandbox"
|
5
|
+
else
|
6
|
+
to="$1"
|
7
|
+
fi
|
8
|
+
|
9
|
+
if [ -d "${to}" ]; then
|
10
|
+
echo "directory ./${to} already exists. quitting."
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
|
14
|
+
echo "==> bundle install"
|
15
|
+
bundle install || exit 1
|
16
|
+
echo "==> mkdir $to && cd $to"
|
17
|
+
mkdir $to || exit 1
|
18
|
+
cd $to || exit 1
|
19
|
+
echo "===> bundle exec ../bin/days init"
|
20
|
+
bundle exec ../bin/days init || exit 1
|
21
|
+
echo "===> Replacing gemfile"
|
22
|
+
cat > Gemfile <<-EOF
|
23
|
+
source "https://rubygems.org"
|
24
|
+
|
25
|
+
gem "days", path: File.expand_path(File.join(__FILE__, '..', '..'))
|
26
|
+
|
27
|
+
group :production do
|
28
|
+
# gem "mysql2"
|
29
|
+
end
|
30
|
+
|
31
|
+
group :development do
|
32
|
+
gem "pry"
|
33
|
+
gem "sqlite3"
|
34
|
+
end
|
35
|
+
EOF
|
36
|
+
echo "===> bundle install"
|
37
|
+
bundle install || exit 1
|
38
|
+
echo "===> bundle exec days migrate"
|
39
|
+
bundle exec days migrate || exit 1
|
40
|
+
|
41
|
+
echo "===== Days environment for development is set up at $(pwd)! ====="
|
data/days.gemspec
CHANGED
@@ -17,8 +17,31 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency "sinatra"
|
20
|
+
gem.add_dependency "sinatra", '~> 1.3.3'
|
21
|
+
gem.add_dependency "thor"
|
22
|
+
gem.add_dependency "rack_csrf"
|
23
|
+
|
24
|
+
gem.add_dependency "settingslogic"
|
25
|
+
|
21
26
|
gem.add_dependency "sprockets"
|
22
27
|
gem.add_dependency "haml"
|
23
|
-
gem.add_dependency "
|
28
|
+
gem.add_dependency "sass"
|
29
|
+
|
30
|
+
gem.add_dependency "redcarpet"
|
31
|
+
gem.add_dependency "builder"
|
32
|
+
|
33
|
+
gem.add_dependency "activerecord", "~> 3.2.9"
|
34
|
+
gem.add_dependency "kaminari", "> 0.13.0"
|
35
|
+
gem.add_dependency "padrino-helpers"
|
36
|
+
gem.add_dependency "stringex"
|
37
|
+
gem.add_dependency "bcrypt-ruby"
|
38
|
+
|
39
|
+
gem.add_development_dependency "sqlite3"
|
40
|
+
|
41
|
+
gem.add_development_dependency "rspec"
|
42
|
+
gem.add_development_dependency "rack-test"
|
43
|
+
gem.add_development_dependency "fuubar"
|
44
|
+
|
45
|
+
gem.add_dependency "pry"
|
46
|
+
gem.add_development_dependency "pry-nav"
|
24
47
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Days
|
2
|
+
class App < Sinatra::Base
|
3
|
+
get "/admin/categories", :admin_only => true do
|
4
|
+
@categories = Category.all
|
5
|
+
haml :'admin/categories', layout: :admin
|
6
|
+
end
|
7
|
+
|
8
|
+
post "/admin/categories", :admin_only => true do
|
9
|
+
category = params[:category] || halt(400)
|
10
|
+
@category = Category.new(category)
|
11
|
+
|
12
|
+
if @category.save
|
13
|
+
redirect "/admin/categories"
|
14
|
+
else
|
15
|
+
status 406
|
16
|
+
@categories = Category.all
|
17
|
+
haml :'admin/categories', layout: :admin
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
put "/admin/categories/:id", :admin_only => true do
|
22
|
+
category = params[:category] || halt(400)
|
23
|
+
@category = Category.where(id: params[:id]).first || halt(404)
|
24
|
+
|
25
|
+
@category.update_attributes(category)
|
26
|
+
|
27
|
+
if @category.save
|
28
|
+
redirect "/admin/categories"
|
29
|
+
else
|
30
|
+
status 406
|
31
|
+
@categories = Category.all
|
32
|
+
haml :'admin/categories', layout: :admin
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
delete "/admin/categories/:id", :admin_only => true do
|
37
|
+
@category = Category.where(id: params[:id]).first || halt(404)
|
38
|
+
@category.destroy
|
39
|
+
|
40
|
+
redirect "/admin/categories"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Days
|
2
|
+
class App < Sinatra::Base
|
3
|
+
get "/admin/entries", :admin_only => true do
|
4
|
+
@entries = Entry.order('id DESC').all
|
5
|
+
haml :'admin/entries/index', layout: :admin
|
6
|
+
end
|
7
|
+
|
8
|
+
get "/admin/entries/new", :admin_only => true do
|
9
|
+
@entry = Entry.new
|
10
|
+
@categories = Category.all
|
11
|
+
haml :'admin/entries/form', layout: :admin
|
12
|
+
end
|
13
|
+
|
14
|
+
post "/admin/entries", :admin_only => true do
|
15
|
+
entry = params[:entry]
|
16
|
+
if entry
|
17
|
+
if entry[:categories].is_a?(Hash)
|
18
|
+
entry[:categories] = Category.where(
|
19
|
+
id: entry[:categories].keys.map(&:to_i)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
@entry = Entry.new(entry)
|
24
|
+
@entry.user = current_user
|
25
|
+
|
26
|
+
if @entry.save
|
27
|
+
redirect "/admin/entries/#{@entry.id}" # FIXME: Permalink
|
28
|
+
else
|
29
|
+
status 406
|
30
|
+
@categories = Category.all
|
31
|
+
haml :'admin/entries/form', layout: :admin
|
32
|
+
end
|
33
|
+
else
|
34
|
+
halt 400
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
get "/admin/entries/:id", :admin_only => true do
|
39
|
+
@entry = Entry.where(id: params[:id]).first || halt(404)
|
40
|
+
@categories = Category.all
|
41
|
+
haml :'admin/entries/form', layout: :admin
|
42
|
+
end
|
43
|
+
|
44
|
+
put "/admin/entries/:id", :admin_only => true do
|
45
|
+
entry = params[:entry] || halt(400)
|
46
|
+
@entry = Entry.where(id: params[:id]).first || halt(404)
|
47
|
+
|
48
|
+
entry[:categories] = Category.where(
|
49
|
+
id: (entry[:categories] || {}).keys.map(&:to_i)
|
50
|
+
)
|
51
|
+
@entry.update_attributes(entry)
|
52
|
+
|
53
|
+
if @entry.save
|
54
|
+
redirect "/admin/entries/#{@entry.id}"
|
55
|
+
else
|
56
|
+
status 406
|
57
|
+
@categories = Category.all
|
58
|
+
haml :'admin/entries/form', layout: :admin
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
delete "/admin/entries/:id", :admin_only => true do
|
63
|
+
@entry = Entry.where(id: params[:id]).first || halt(404)
|
64
|
+
@entry.destroy
|
65
|
+
|
66
|
+
redirect "/admin/entries"
|
67
|
+
end
|
68
|
+
|
69
|
+
post "/admin/entries/preview", :admin_only => true do
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Days
|
2
|
+
class App < Sinatra::Base
|
3
|
+
get "/admin/login" do
|
4
|
+
haml :'admin/login'
|
5
|
+
end
|
6
|
+
|
7
|
+
post "/admin/login" do
|
8
|
+
unless params[:login_name] && params[:password]
|
9
|
+
halt 400
|
10
|
+
end
|
11
|
+
|
12
|
+
user = User.where(login_name: params[:login_name]).first
|
13
|
+
|
14
|
+
if user && user.authenticate(params[:password])
|
15
|
+
session[:user_id] = user.id
|
16
|
+
redirect '/admin'
|
17
|
+
else
|
18
|
+
status 401
|
19
|
+
haml :'admin/login'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
post "/admin/logout" do
|
24
|
+
session[:user_id] = nil
|
25
|
+
redirect '/admin/login'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Days
|
2
|
+
class App < Sinatra::Base
|
3
|
+
get "/admin/setup", :setup_only => true do
|
4
|
+
@user = User.new
|
5
|
+
haml :'admin/setup'
|
6
|
+
end
|
7
|
+
|
8
|
+
post "/admin/setup", :setup_only => true do
|
9
|
+
user = params[:user] || halt(400)
|
10
|
+
@user = User.new(user)
|
11
|
+
if @user.save
|
12
|
+
session[:user_id] = @user.id
|
13
|
+
redirect '/admin'
|
14
|
+
else
|
15
|
+
status 406
|
16
|
+
haml :'admin/setup'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Days
|
2
|
+
class App < Sinatra::Base
|
3
|
+
get "/admin/users", :admin_only => true do
|
4
|
+
@users = User.all
|
5
|
+
haml :'admin/users/index', layout: :admin
|
6
|
+
end
|
7
|
+
|
8
|
+
get "/admin/users/new", :admin_only => true do
|
9
|
+
@user = User.new
|
10
|
+
haml :'admin/users/form', layout: :admin
|
11
|
+
end
|
12
|
+
|
13
|
+
post "/admin/users", :admin_only => true do
|
14
|
+
user = params[:user] || halt(400)
|
15
|
+
@user = User.new(user)
|
16
|
+
|
17
|
+
if @user.save
|
18
|
+
redirect "/admin/users/#{@user.id}" # FIXME: Permalink
|
19
|
+
else
|
20
|
+
status 406
|
21
|
+
haml :'admin/users/form', layout: :admin
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
get "/admin/users/:id", :admin_only => true do
|
26
|
+
@user = User.where(id: params[:id]).first || halt(404)
|
27
|
+
haml :'admin/users/form', layout: :admin
|
28
|
+
end
|
29
|
+
|
30
|
+
put "/admin/users/:id", :admin_only => true do
|
31
|
+
user = params[:user] || halt(400)
|
32
|
+
@user = User.where(id: params[:id]).first || halt(404)
|
33
|
+
|
34
|
+
if user[:password] == ""
|
35
|
+
user.delete :password
|
36
|
+
end
|
37
|
+
|
38
|
+
@user.update_attributes(user)
|
39
|
+
|
40
|
+
if @user.save
|
41
|
+
redirect "/admin/users/#{@user.id}"
|
42
|
+
else
|
43
|
+
status 406
|
44
|
+
haml :'admin/users/form', layout: :admin
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
delete "/admin/users/:id", :admin_only => true do
|
49
|
+
@user = User.where(id: params[:id]).first || halt(404)
|
50
|
+
|
51
|
+
if @user == current_user
|
52
|
+
halt 400
|
53
|
+
else
|
54
|
+
@user.destroy
|
55
|
+
redirect "/admin/users"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'active_support/core_ext/time/calculations'
|
3
|
+
|
4
|
+
module Days
|
5
|
+
class App < Sinatra::Base
|
6
|
+
not_found do
|
7
|
+
entry = lookup_entry(request.path)
|
8
|
+
|
9
|
+
if entry
|
10
|
+
status 200
|
11
|
+
|
12
|
+
case entry
|
13
|
+
when Array
|
14
|
+
@title = entry.map(&:title).join(', ')
|
15
|
+
@entries = entry
|
16
|
+
haml :entries
|
17
|
+
when Entry
|
18
|
+
@title = entry.title
|
19
|
+
haml :entry, locals: {entry: entry, full: true}
|
20
|
+
end
|
21
|
+
else
|
22
|
+
''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
get '/' do
|
27
|
+
@entries = Entry.published.page(params[:page] || 1)
|
28
|
+
haml :entries
|
29
|
+
end
|
30
|
+
|
31
|
+
get '/category/:name' do
|
32
|
+
category = Category.where(name: params[:name]).first || halt(404)
|
33
|
+
@entries = category.entries.published.page(params[:page] || 1)
|
34
|
+
haml :entries
|
35
|
+
end
|
36
|
+
|
37
|
+
get '/:year/:month' do
|
38
|
+
halt 404 if /[^0-9]/ =~ params[:year] || /[^0-9]/ =~ params[:month]
|
39
|
+
begin
|
40
|
+
base = Time.local(params[:year].to_i, params[:month].to_i, 1, 0, 0, 0)
|
41
|
+
rescue ArgumentError
|
42
|
+
halt 404
|
43
|
+
end
|
44
|
+
|
45
|
+
range = (base.beginning_of_month .. base.end_of_month)
|
46
|
+
@entries = Entry.where(published_at: range).published.page(params[:page] || 1)
|
47
|
+
haml :entries
|
48
|
+
end
|
49
|
+
|
50
|
+
get '/feed' do
|
51
|
+
content_type 'application/atom+xml'
|
52
|
+
entries = Entry.published.first(50)
|
53
|
+
|
54
|
+
xml = Builder::XmlMarkup.new
|
55
|
+
|
56
|
+
xml.instruct!
|
57
|
+
|
58
|
+
xml.feed("xmlns" => 'http://www.w3.org/2005/Atom') do
|
59
|
+
xml.id("tag:#{request.host},2005:#{request.fullpath.split(".")[0]}")
|
60
|
+
|
61
|
+
xml.link(:rel => 'alternate', :type => 'text/html', :href => request.url.gsub(/feed$/,''))
|
62
|
+
xml.link(:rel => 'self', :type => 'application/atom+xml', :href => request.url)
|
63
|
+
xml.title config.title
|
64
|
+
|
65
|
+
xml.updated(entries.map(&:updated_at).max)
|
66
|
+
|
67
|
+
entries.each do |entry|
|
68
|
+
xml.entry do
|
69
|
+
xml.id "tag:#{request.host},2005:Entry/#{entry.id}"
|
70
|
+
|
71
|
+
xml.published entry.published_at.xmlschema
|
72
|
+
xml.updated entry.updated_at.xmlschema
|
73
|
+
|
74
|
+
xml.link(rel: 'alternate', type: 'text/html', href: "#{request.url.gsub(/\/feed$/,'')}#{entry_path(entry)}")
|
75
|
+
|
76
|
+
xml.title entry.title
|
77
|
+
|
78
|
+
xml.content(entry.short_rendered { '... <a href="'+entry_path(entry)+'">Continue Reading</a>' }, type: 'html')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/days/app.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'kaminari/sinatra'
|
3
|
+
require 'sprockets'
|
4
|
+
require 'rack/csrf'
|
5
|
+
require_relative 'config'
|
6
|
+
require_relative 'models'
|
7
|
+
require_relative 'helpers'
|
8
|
+
require 'haml'
|
9
|
+
require 'sass'
|
10
|
+
|
11
|
+
I18n.load_path.reject! {|_| _.match(/padrino/) }
|
12
|
+
|
13
|
+
module Days
|
14
|
+
class App < Sinatra::Base
|
15
|
+
set :root, File.expand_path(File.join(__FILE__, '..', '..', '..', 'app'))
|
16
|
+
|
17
|
+
set(:sprockets, Sprockets::Environment.new.tap { |env|
|
18
|
+
env.append_path "#{self.root}/javascripts"
|
19
|
+
env.append_path "#{self.root}/stylesheets"
|
20
|
+
env.append_path "#{self.root}/images"
|
21
|
+
})
|
22
|
+
|
23
|
+
|
24
|
+
def self.rack
|
25
|
+
Rack::Builder.app {
|
26
|
+
app = ::Days::App
|
27
|
+
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
28
|
+
|
29
|
+
map '/' do
|
30
|
+
if app.environment != 'test'
|
31
|
+
use Rack::Session::Cookie
|
32
|
+
use Rack::Csrf
|
33
|
+
end
|
34
|
+
if app.environment == 'development'
|
35
|
+
app.dump_errors = true
|
36
|
+
app.show_exceptions = true
|
37
|
+
app.reload_templates = true
|
38
|
+
end
|
39
|
+
run app
|
40
|
+
end
|
41
|
+
|
42
|
+
map '/assets' do
|
43
|
+
run app.sprockets
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
set(:config, nil)
|
49
|
+
set :method_override, true
|
50
|
+
|
51
|
+
set :haml, :escape_html => true
|
52
|
+
|
53
|
+
helpers Helpers
|
54
|
+
helpers Kaminari::Helpers::SinatraHelpers
|
55
|
+
|
56
|
+
set :admin_only do |_|
|
57
|
+
condition do
|
58
|
+
unless logged_in?
|
59
|
+
# TODO: return-path param
|
60
|
+
redirect '/admin/login'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
set :setup_only do |_|
|
66
|
+
condition do
|
67
|
+
if User.first
|
68
|
+
halt 403
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
alias find_template_orig find_template
|
74
|
+
def find_template(views, name, engine, &block)
|
75
|
+
app_views = File.expand_path(settings.config['views'] || ::File.join(settings.config.root, "views"))
|
76
|
+
find_template_orig app_views, name, engine, &block
|
77
|
+
find_template_orig views, name, engine, &block
|
78
|
+
end
|
79
|
+
|
80
|
+
class << self
|
81
|
+
alias environment_orig= environment=
|
82
|
+
def environment=(x)
|
83
|
+
self.environment_orig = x
|
84
|
+
Config.namespace x.to_s
|
85
|
+
x
|
86
|
+
end
|
87
|
+
|
88
|
+
alias config_orig= config=
|
89
|
+
def config=(x)
|
90
|
+
self.config_orig = x
|
91
|
+
self.set :session_secret, config['session_secret'] || 'jjiw-jewn-n2i9-nc1e_binding.pry-is-good'
|
92
|
+
self.set(:sprockets, Sprockets::Environment.new.tap { |env|
|
93
|
+
env.append_path "#{config.root}/javascripts"
|
94
|
+
env.append_path "#{config.root}/stylesheets"
|
95
|
+
env.append_path "#{config.root}/images"
|
96
|
+
env.append_path "#{self.root}/javascripts"
|
97
|
+
env.append_path "#{self.root}/stylesheets"
|
98
|
+
env.append_path "#{self.root}/images"
|
99
|
+
})
|
100
|
+
config.establish_db_connection()
|
101
|
+
x
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
Dir["#{File.dirname(__FILE__)}/app/**/*.rb"].each do |f|
|
108
|
+
require f
|
109
|
+
end
|
110
|
+
|