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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 169c4477ec511b09e0a7704c632f4601401a52f1
4
- data.tar.gz: 8d2480c30354ccb9ff725615e90920144294c218
3
+ metadata.gz: b0bfb4f0326a20c37b1ee6f7615986a83e9210a6
4
+ data.tar.gz: 01a5e1f4c3834cb889c10318d230c28fd8f358a1
5
5
  SHA512:
6
- metadata.gz: 94dc6f30ef38e2e035fdd7b737285ec46e49860b6538bb4f252dca998f36fd38fb88766f4914a5ccf29c69fb6e5afffcca184edb18b0c6b354ccb1ab4839a5d5
7
- data.tar.gz: 8bf1bf2fb71743d589e4f7cc7578207af1553f1725fce7a17e20e23324e3a110d708cc2036a5525e92419b76835575d25174d7cc47ead4a2a30bc9671ebd770d
6
+ metadata.gz: 573a00980ec9a68e0077466f408bb066ee3ed7516380d9cdd7b2de251d38f7b38b327a4785e37f0bfa4b0c45cf9d2773cc2d53c85bad9fdfecc516c142ac39a1
7
+ data.tar.gz: aac4615283d5c0fc94ac9c5866387e0f53dabce7c4c103c62bc934da7e1b04390005721cd5f7fc793f79e69ac3dac675554f9b7f436f3e72e18a101e1e329abf
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: yXIkwXyJxv4u8MsUbhz7Y33AawuxQ9qez
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
  gem 'sinatra'
6
6
  gem 'slim'
7
7
  gem 'sass'
8
- gem 'compass'
8
+ gem 'compass'
9
+ gem 'coveralls', require: false
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)
@@ -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
- p configuration_file
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 += "Database configuration file not found."
13
+ @errors.push "Database configuration file not found."
15
14
  false
16
- rescue => e
17
- @errors += e.to_s
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
@@ -1,8 +1,37 @@
1
1
  module Story
2
2
  module Meta
3
3
  NAME = 'story'
4
- VERSION = '0.0.4'
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
@@ -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
- set :views, settings.views.to_s.gsub(/views$/, '/templates/story')
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
- raise error @errors if not db_connected?
17
- @title = settings.blog_title
18
- @header_needed = @footer_needed = true
19
- @additional_styles ||= load_additional_styles
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
- error do |*errors|
37
- @errors = errors
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
- p == error
3
- br
1
+ - @errors.flatten.each do |error|
2
+ b == error
@@ -0,0 +1 @@
1
+ | footer
@@ -0,0 +1 @@
1
+ | header
@@ -1,9 +1,11 @@
1
1
  doctype html
2
2
  html
3
3
  head
4
- title = settings.blog_title
4
+ title == @title
5
5
  == slim :meta
6
6
  == slim :styles
7
7
  == slim :scripts
8
8
  body
9
- == yield
9
+ == slim :header if @header_needed
10
+ == yield
11
+ == slim :footer if @footer_needed
@@ -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
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-14 00:00:00.000000000 Z
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