story 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +2 -0
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/lib/story/db/utils.rb +48 -6
- data/lib/story/meta.rb +30 -1
- data/lib/story/router.rb +28 -7
- data/lib/story/templates/story/error_page.slim +2 -3
- data/lib/story/templates/story/footer.slim +1 -0
- data/lib/story/templates/story/header.slim +1 -0
- data/lib/story/templates/story/layout.slim +4 -2
- data/lib/story/utils.rb +12 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0bfb4f0326a20c37b1ee6f7615986a83e9210a6
|
4
|
+
data.tar.gz: 01a5e1f4c3834cb889c10318d230c28fd8f358a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573a00980ec9a68e0077466f408bb066ee3ed7516380d9cdd7b2de251d38f7b38b327a4785e37f0bfa4b0c45cf9d2773cc2d53c85bad9fdfecc516c142ac39a1
|
7
|
+
data.tar.gz: aac4615283d5c0fc94ac9c5866387e0f53dabce7c4c103c62bc934da7e1b04390005721cd5f7fc793f79e69ac3dac675554f9b7f436f3e72e18a101e1e329abf
|
data/.coveralls.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Story
|
2
|
-
[![Gem Version](https://badge.fury.io/rb/story.png)](http://badge.fury.io/rb/story) [![Code Climate](https://codeclimate.com/github/rozzy/story.png)](https://codeclimate.com/github/rozzy/story) [![Dependency Status](https://gemnasium.com/rozzy/story.png)](https://gemnasium.com/rozzy/story)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/story.png)](http://badge.fury.io/rb/story) [![Code Climate](https://codeclimate.com/github/rozzy/story.png)](https://codeclimate.com/github/rozzy/story) [![Dependency Status](https://gemnasium.com/rozzy/story.png)](https://gemnasium.com/rozzy/story) [![Coverage Status](https://coveralls.io/repos/rozzy/story/badge.png)](https://coveralls.io/r/rozzy/story)
|
3
3
|
Gem for creating awesome personal blog.
|
4
4
|
|
5
5
|
[Installing](#installation)
|
data/lib/story/db/utils.rb
CHANGED
@@ -2,22 +2,64 @@ module Story
|
|
2
2
|
module DB
|
3
3
|
module Utils
|
4
4
|
def db_connected?
|
5
|
-
@errors ||=
|
5
|
+
@errors ||= []
|
6
6
|
begin
|
7
7
|
configuration_file = File.exists?('dbconfig.yml') ? 'dbconfig.yml' : File.join(File.dirname(__FILE__), 'config.yml')
|
8
|
-
|
9
|
-
dbconfig = YAML::load File.open configuration_file
|
8
|
+
dbconfig = parse_configuration_from configuration_file
|
10
9
|
ActiveRecord::Base.logger = Logger.new STDERR
|
11
10
|
ActiveRecord::Base.establish_connection dbconfig
|
12
11
|
true
|
13
12
|
rescue Errno::ENOENT
|
14
|
-
@errors
|
13
|
+
@errors.push "Database configuration file not found."
|
15
14
|
false
|
16
|
-
rescue => e
|
17
|
-
@errors
|
15
|
+
rescue Errors::DatabaseError => e
|
16
|
+
@errors.push e.message
|
18
17
|
false
|
19
18
|
end
|
20
19
|
end
|
20
|
+
|
21
|
+
def sinatra_setting_exists? setting
|
22
|
+
settings.respond_to? setting
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_list_of_db_adapters
|
26
|
+
["jdbc", "fb", "frontbase", "mysql", "openbase", "oci", "postgresql", "sqlite3", "sqlite2", "sqlite", "sqlserver", "sybsql"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def concat_default_and_user_adapters?
|
30
|
+
sinatra_setting_exists? :db_adapters and settings.db_adapters.select { |b| b.is_a? (String) }.size > 0 and settings.db_adapters.is_a? (Array)
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_adapters
|
34
|
+
default_adapters = get_list_of_db_adapters
|
35
|
+
if concat_default_and_user_adapters? then default_adapters.concat(settings.db_adapters.each(&:downcase!))
|
36
|
+
else default_adapters end
|
37
|
+
end
|
38
|
+
|
39
|
+
def define_db_error_type adapters, config
|
40
|
+
case
|
41
|
+
when !config.has_key?("adapter") && !adapters.include?(config["adapter"].downcase) then 0
|
42
|
+
when !config.has_key?("adapter") then 1
|
43
|
+
when !config.has_key?("database") then 2
|
44
|
+
when !config.has_key?("adapter") && !config.has_key?("database") then 3
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def some_db_errors_in? config
|
49
|
+
adapters = parse_adapters
|
50
|
+
errors_found = !config.has_key?("adapter") or !config.has_key?("database") or !(config.has_key?("adapter") and adapters.include?(config["adapter"].downcase))
|
51
|
+
if errors_found then
|
52
|
+
@db_error_type = define_db_error_type adapters, config
|
53
|
+
end
|
54
|
+
errors_found
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_configuration_from file
|
58
|
+
config = YAML::load File.open file
|
59
|
+
error_types = ["unsupported_db_adapter", "no_db_adapter_specified", "no_database_specified", "no_db_adapter_and_database_specified"]
|
60
|
+
raise Errors::DatabaseError, send("raise_#{error_types[@db_error_type]}".to_sym, file, config) if some_db_errors_in? config
|
61
|
+
config
|
62
|
+
end
|
21
63
|
end
|
22
64
|
end
|
23
65
|
end
|
data/lib/story/meta.rb
CHANGED
@@ -1,8 +1,37 @@
|
|
1
1
|
module Story
|
2
2
|
module Meta
|
3
3
|
NAME = 'story'
|
4
|
-
VERSION = '0.0.
|
4
|
+
VERSION = '0.0.5'
|
5
5
|
CHARSET = 'utf-8'
|
6
6
|
DEFAULT_BLOG_TITLE = 'Personal Blog'
|
7
7
|
end
|
8
|
+
|
9
|
+
module Errors
|
10
|
+
class DatabaseError < Exception; end
|
11
|
+
class ConnectionError < Exception; end
|
12
|
+
|
13
|
+
def print_config_file_location
|
14
|
+
"#{"STORY_GEM_ROOT/" if !(/#{Gem.dir}/ =~ file).is_a? NilClass }#{File.basename(File.dirname(file))}/#{File.basename(file)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def raise_unsupported_db_adapter file, config
|
18
|
+
"Unsupported database adapter <b>#{config["adapter"]}</b> in database config file (#{print_config_file_location})."
|
19
|
+
end
|
20
|
+
|
21
|
+
def raise_no_db_adapter_specified file, config
|
22
|
+
"No database adapter specified in database config file (#{print_config_file_location})."
|
23
|
+
end
|
24
|
+
|
25
|
+
def raise_no_database_specified file, config
|
26
|
+
"No database file or data specified in database config file (#{print_config_file_location})."
|
27
|
+
end
|
28
|
+
|
29
|
+
def raise_no_db_adapter_and_database_specified file, config
|
30
|
+
"No database file and data specified in database config file (#{print_config_file_location})."
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_on_error_page
|
34
|
+
@on_error_page = request.path_info.downcase.match "/e_([a-z0-9_]+)"
|
35
|
+
end
|
36
|
+
end
|
8
37
|
end
|
data/lib/story/router.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module Story
|
2
2
|
class Base < Sinatra::Base
|
3
3
|
include Utils
|
4
|
+
include Errors
|
4
5
|
include DB::Utils
|
5
6
|
|
6
7
|
configure do
|
7
|
-
|
8
|
+
enable :show_exceptions
|
9
|
+
set :environment, :development
|
10
|
+
set :views, settings.views.to_s.gsub(/views$/, 'templates/story')
|
8
11
|
set :blog_title, Meta::DEFAULT_BLOG_TITLE
|
9
12
|
set :charset, Meta::CHARSET
|
10
13
|
set :static_ext, ''
|
@@ -13,10 +16,16 @@ module Story
|
|
13
16
|
end
|
14
17
|
|
15
18
|
before do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
begin
|
20
|
+
@title = settings.blog_title
|
21
|
+
@header_needed = @footer_needed = true
|
22
|
+
@additional_styles ||= load_additional_styles
|
23
|
+
raise ConnectionError if not db_connected?
|
24
|
+
get_last_session_url
|
25
|
+
rescue ConnectionError => e
|
26
|
+
check_on_error_page
|
27
|
+
if not @on_error_page then redirect '/e_config' end
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
31
|
get %r{(.*\..*)} do |url|
|
@@ -33,12 +42,24 @@ module Story
|
|
33
42
|
slim :index
|
34
43
|
end
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
get %r{e([0-9]+)} do |error|
|
46
|
+
status error
|
38
47
|
slim :error_page
|
39
48
|
end
|
40
49
|
|
50
|
+
get %r{e_([a-zA-Z0-9_]+)} do |error|
|
51
|
+
redirect @last_session != request.path_info ? @last_session : '/' if @errors.size == 0
|
52
|
+
title @errors.size > 0 ? @errors.first : "Error occured"
|
53
|
+
title_type :error
|
54
|
+
slim :error_page
|
55
|
+
end
|
56
|
+
|
57
|
+
after do
|
58
|
+
set_session_url
|
59
|
+
end
|
60
|
+
|
41
61
|
not_found do
|
62
|
+
status 404
|
42
63
|
title "404"
|
43
64
|
'Page not found'
|
44
65
|
end
|
@@ -1,3 +1,2 @@
|
|
1
|
-
- @errors.each do |error|
|
2
|
-
|
3
|
-
br
|
1
|
+
- @errors.flatten.each do |error|
|
2
|
+
b == error
|
@@ -0,0 +1 @@
|
|
1
|
+
| footer
|
@@ -0,0 +1 @@
|
|
1
|
+
| header
|
data/lib/story/utils.rb
CHANGED
@@ -19,6 +19,18 @@ module Story
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def title_type type_given = false
|
23
|
+
@title = "(#{type_given}) #{@title}" if type_given
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_last_session_url
|
27
|
+
@last_session = request.cookies["session_url"] != "" ? request.cookies["session_url"] : '/'
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_session_url
|
31
|
+
response.set_cookie "session_url", request.path_info if !(request.path_info.match /^e_/).is_a? NilClass and @last_session != request.path_info
|
32
|
+
end
|
33
|
+
|
22
34
|
def parse_file filename, extension = '', root = true
|
23
35
|
file_path = "#{'.' if root}#{filename}.#{extension}"
|
24
36
|
raise not_found if not File.exists? file_path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: story
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rozzy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -101,6 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- .coveralls.yml
|
104
105
|
- .gitignore
|
105
106
|
- Gemfile
|
106
107
|
- LICENSE.txt
|
@@ -112,6 +113,8 @@ files:
|
|
112
113
|
- lib/story/meta.rb
|
113
114
|
- lib/story/router.rb
|
114
115
|
- lib/story/templates/story/error_page.slim
|
116
|
+
- lib/story/templates/story/footer.slim
|
117
|
+
- lib/story/templates/story/header.slim
|
115
118
|
- lib/story/templates/story/index.slim
|
116
119
|
- lib/story/templates/story/layout.slim
|
117
120
|
- lib/story/templates/story/meta.slim
|