-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 29ea4ed
Showing
28 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Small blog written in Ruby (Sinatra, Haml+Sass, Activerecord) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'rubygems' | ||
require 'spec/rake/spectask' | ||
require 'sinatra' | ||
|
||
|
||
Spec::Rake::SpecTask.new do |t| | ||
t.ruby_opts = ['-rtest/unit'] | ||
t.spec_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
|
||
|
||
namespace 'db' do | ||
task :create do | ||
require 'activerecord' | ||
|
||
ActiveRecord::Base.establish_connection( | ||
:adapter => 'mysql', | ||
:encoding => 'utf8', | ||
:username => 'root', | ||
:host => 'localhost', | ||
:socket => '/var/lib/mysql/mysql.sock', | ||
:database => 'blog_development' | ||
) | ||
|
||
ActiveRecord::Migration.create_table :posts do |t| | ||
t.string :title | ||
t.text :body | ||
|
||
t.timestamps | ||
end | ||
|
||
ActiveRecord::Migration.create_table :comments do |t| | ||
t.text :body | ||
t.integer :post_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
end | ||
|
||
namespace 'gems' do | ||
task :install do | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
get '/about' do | ||
haml :about_me | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'activerecord' | ||
|
||
require 'schema/schema.rb' | ||
|
||
require 'util/flash.rb' | ||
require 'util/sessions.rb' | ||
|
||
get '/blog' do | ||
@posts = Post.all() | ||
haml :blog, :layout => :layout_blog | ||
end | ||
|
||
get '/posts/add' do secure | ||
haml :post_add | ||
end | ||
|
||
post '/posts/add' do secure | ||
Post.create(:title => params[:title], :body => params[:body]) | ||
set_flash 'New post created' | ||
redirect '/blog' | ||
end | ||
|
||
get '/posts/edit/:id' do secure | ||
@post = Post.find(params[:id]) | ||
haml :post_edit | ||
end | ||
|
||
post '/posts/edit/:id' do secure | ||
post = Post.find(params[:id]) | ||
post.title = params[:title] | ||
post.body = params[:body] | ||
post.save | ||
set_flash 'Post updated' | ||
redirect '/blog' | ||
end | ||
|
||
get '/posts/delete/:id' do secure | ||
Post.delete(params[:id]) | ||
set_flash 'Post was deleted' | ||
redirect '/blog' | ||
end | ||
|
||
get '/posts/:id' do | ||
@post = Post.find(params[:id]) | ||
haml :post_view, :layout => :layout_blog | ||
end | ||
|
||
post '/posts/:id/add_comment' do | ||
post = Post.find(params[:id]) | ||
post.comments.create(:body => params[:body]) | ||
set_flash 'Comment added' | ||
redirect '/posts/' + params[:id] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set :app_file, File.expand_path(File.dirname(__FILE__) + '/../main.rb') | ||
set :public, File.expand_path(File.dirname(__FILE__) + '/../public') | ||
set :views, File.expand_path(File.dirname(__FILE__) + '/../views') | ||
set :env, :production | ||
disable :run, :reload | ||
|
||
require File.dirname(__FILE__) + "/../main" | ||
|
||
run Sinatra.application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
configure :development do | ||
ActiveRecord::Base.establish_connection( | ||
:adapter => 'mysql', | ||
:encoding => 'utf8', | ||
:username => 'root', | ||
:host => 'localhost', | ||
:socket => '/var/lib/mysql/mysql.sock', | ||
:database => 'blog_development' | ||
) | ||
|
||
enable :sessions | ||
end | ||
|
||
configure :test do | ||
ActiveRecord::Base.establish_connection( | ||
:adapter => 'mysql', | ||
:encoding => 'utf8', | ||
:username => 'root', | ||
:host => 'localhost', | ||
:socket => '/var/lib/mysql/mysql.sock', | ||
:database => 'blog_development' | ||
) | ||
|
||
enable :sessions | ||
end | ||
|
||
configure :development_home do #home | ||
ActiveRecord::Base.establish_connection( | ||
:adapter => 'mysql', | ||
:encoding => 'utf8', | ||
:username => 'root', | ||
:password => '1', | ||
:host => 'localhost', | ||
:socket => '/var/run/mysqld/mysqld.sock', | ||
:database => 'blog_development' | ||
) | ||
|
||
enable :sessions | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
get '/gallery' do | ||
haml :gallery | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rubygems' | ||
require 'haml' | ||
|
||
helpers do | ||
def partial(page, options={}) | ||
haml page, options.merge!(:layout => false) | ||
end | ||
|
||
def for_me(text) | ||
if (@is_admin) then | ||
engine = Haml::Engine.new(text) | ||
return engine.render | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
get '/login' do | ||
haml :login | ||
end | ||
|
||
post '/login' do | ||
if authenticate(params["password"]) | ||
redirect '/' | ||
else | ||
'Fuck you bitch!' | ||
end | ||
end | ||
|
||
get '/logout' do | ||
logout | ||
redirect '/' | ||
end | ||
|
||
get '/version' do | ||
Sinatra::VERSION | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'activerecord' | ||
|
||
require 'util/flash.rb' | ||
|
||
load 'configuration.rb' | ||
load 'helpers.rb' | ||
|
||
before do | ||
@flash = get_flash | ||
@is_admin = session["i_am"] | ||
end | ||
|
||
get '/style.css' do | ||
content_type 'text/css' | ||
sass :style | ||
end | ||
|
||
get '/' do | ||
redirect '/about' | ||
end | ||
|
||
load 'login.rb' | ||
load 'about.rb' | ||
load 'gallery.rb' | ||
load 'blog.rb' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Post < ActiveRecord::Base | ||
has_many :comments | ||
end | ||
|
||
class Comment < ActiveRecord::Base | ||
belongs_to :post | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'sinatra/test/rspec' | ||
|
||
load 'main.rb' | ||
|
||
describe 'My fucking site' do | ||
it 'should show the about me page with my nice face' do | ||
get '/blog' | ||
print @response.inspect | ||
@response.should be_ok | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'sinatra' | ||
|
||
def get_flash | ||
flash = request.cookies["flash"] | ||
response.delete_cookie("flash") | ||
return flash | ||
end | ||
|
||
def set_flash(message) | ||
set_cookie("flash", :value => message, :path => '/') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def authenticate(password) | ||
if 'fuck' == password then | ||
session["i_am"] = true | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def logout | ||
session["i_am"] = false | ||
end | ||
|
||
def secure | ||
redirect '/' if not @is_admin | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#navigation | ||
%a{ :id => "t-about", :href => '/about' } About Me | ||
%a{ :id => "t-blog", :href => '/blog' } Blog | ||
%a{ :id => "t-gallery", :href => '/gallery' } Gallery | ||
= for_me "%a{ :href => '/logout' } Logout" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
!!! | ||
%html | ||
%meta{"http-equiv" => 'Content-Type', "content" => 'text/html'} | ||
%head | ||
%title Igor Afonov | ||
%link{ :rel=>"stylesheet", :href=>"/style.css", :type=>"text/css"} | ||
%body{ :id => "about" } | ||
= partial :_navigation | ||
%p | ||
%img{ :id => 'me', :src => '/me.jpg', :align => 'right' } | ||
.mark Education | ||
%p I was born in Donetsk in 1985. In 2007 I've graduated from Donetsk National Technical University (I've recieved master degree in CS and bachelor degree in buisness managment)...... | ||
%p I'm working as software developer..... Software development for me is more than just a work - it's my hobby. Specific areas of my professional interest include: | ||
.mark Interests | ||
Java - I have 2 years expirience in working with C++ (I've developed an enterprise 3D CAD system) and C++. Migrating from C++ to Java was like migrating from ... to ... | ||
%ul | ||
%li Java itself | ||
%li Dependency injection containers (Google Guice, Tapestry IoC). I have expirience in building my own, custom IoC container based on annotations. | ||
%li Dynamic languages built on top of JVM (Groovy, JRuby). | ||
%li Web-frameworks: Tapestry 5, custom made frameworks.... | ||
Ruby - the main feature of ruby that attracts me is its outstanding flexibilty and code expressiveness.... | ||
%ul | ||
%li | ||
Ligtweight web-framework Sinatra (This site is powered by Sinatra, | ||
%a{ :href => "/" } Read more... | ||
) | ||
%li Haml+Sass template engine | ||
C++ | ||
%ul | ||
%li I've worked for 1.5 years with C++ building 3D CAD application | ||
%p | ||
%p | ||
You can contact me by | ||
%a{:href => "mailto:afonov@gmail.com"} afonov@gmail.com | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- for post in @posts | ||
.post | ||
.mark 22.01.2008 | ||
.post-title | ||
%a{:href => "posts/#{post.id}"}= post.title | ||
.post-body= post.body | ||
.post-footer | ||
%a{:href => "posts/#{post.id}#comments"}= "Comments(#{post.comments.count})" | ||
= for_me "%a{ :href => 'posts/edit/#{post.id}' } Edit" | ||
= for_me "%a{ :href => 'posts/delete/#{post.id}' } Delete" | ||
|
||
= for_me "%a{ :href => 'posts/add' } Add new post" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
!!! | ||
%html | ||
%meta{"http-equiv" => 'Content-Type', "content" => 'text/html'} | ||
%head | ||
%title Micro blog | ||
%link{ :rel=>"stylesheet", :href=>"/style.css", :type=>"text/css"} | ||
%body{ :id => "gallery" } | ||
= partial :_navigation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
!!! | ||
%html | ||
%meta{"http-equiv" => 'Content-Type', "content" => 'text/html'} | ||
%head | ||
%link{ :rel=>"stylesheet", :href=>"/style.css", :type=>"text/css"} | ||
%body{ :id => "blog" } | ||
= partial :_navigation | ||
%br | ||
#flash= @flash | ||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h2>Hi %username%!</h2> | ||
%form{:method => "post"} | ||
%input{:name => "password", :type => "password"} | ||
%input{:type => "submit", :value => "Go!"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%h3 Adding new post: | ||
|
||
%form{ :action => "add", :method => "post"} | ||
Title: | ||
%input{:name => "title"} | ||
%br | ||
Body: | ||
%textarea{:name=>"body", :cols => 80, :rows => 40} | ||
%br | ||
%input{:type=>"submit"} |
Oops, something went wrong.