rubko 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 507cef7351098c01960413739e54b19d74ea872d
4
- data.tar.gz: b6476fac467d2265b8777620e77b9557fc16e19f
3
+ metadata.gz: 6dda5882684cd22f6df19f6aae673980ab60b223
4
+ data.tar.gz: 2e480c180915d74789de1f3085787224726a8eb2
5
5
  SHA512:
6
- metadata.gz: 926e843d6848ceb3dccb87affd87b1c57998a8d38822517e2cbc02ef077cdde55fb2944d62741c7b67e04388cc2fcf6deea4b5fe59626fa47cf5ca33ce0ca19d
7
- data.tar.gz: 35f3021ce7bae47895be95216f0358314dd93a5c47b972d94540aa0df94dfdfac662a1768f610c67a5ed37007fbf4f3342cc81650192dfa134be946c0905d032
6
+ metadata.gz: 1c6fcdc3e99d8bb505c778c9e7ae0c4b832506231fb4467b33a55ba5ca84e1b048b7505c392d86719c0bb06fa4b257a95b6e1904cf2e9a989c8e09876bd4a6ac
7
+ data.tar.gz: 22dd3ac23cca2ec497f613c1c4589bba902f4d7237f6eda55a3811f9ffdc69e9e3f933f4959eadda4a961cb9ecb0ac20ac5cf7301cf5513b853a971c969686d9
@@ -1,40 +1,50 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- # settings
4
-
5
- ssh = true
6
- host = 'hetzner:54321'
7
- user = 'root'
8
- remote = '/srv/http/' + File.basename(Dir.getwd)
9
-
10
- exclude = [
11
- 'log.txt',
12
- #'config/db.rb',
13
- '.deploy.rb',
14
- '.dev/',
15
- '.run/',
16
- '.repo/',
17
- '.gitignore',
18
- '.git/'
19
- ]
20
-
21
- # program
22
-
23
- require 'io/console'
24
- print 'Password: ';
25
- pass = STDIN.noecho(&:gets).strip
26
- puts
27
-
28
- protocol = ssh ? 'sftp' : 'ftp'
29
-
30
- commands = [
31
- 'set ftp:list-options -a',
32
- "open #{protocol}://#{user}:#{pass}@#{host}",
33
- 'lcd ./',
34
- "cd #{remote}",
35
- 'mirror -L --reverse --only-newer --verbose ' + exclude.map { |el|
36
- '--exclude-glob ' + el
37
- }.join(' ')
38
- ]
39
-
40
- system 'lftp', '-c', commands.join(';')
3
+ require 'rubko'
4
+
5
+ class Rubko::Deploy
6
+ def initialize
7
+ @protocol = :sftp # :ftp
8
+ @remote = "/srv/http/#{File.basename Dir.getwd}"
9
+
10
+ @exclude = [
11
+ '.dev/',
12
+ '.run/',
13
+ '.repo/',
14
+ '.gitignore',
15
+ '.git/'
16
+ ]
17
+ end
18
+
19
+ attr_reader :protocol, :remote, :user, :host, :exclude
20
+
21
+ def password
22
+ return @password if @password
23
+
24
+ require 'io/console'
25
+ print 'Password: ';
26
+ STDIN.noecho(&:gets).strip.tap {
27
+ puts
28
+ }
29
+ end
30
+
31
+ def deploy!
32
+ config
33
+
34
+ commands = [
35
+ 'set ftp:list-options -a',
36
+ "open #{protocol}://#{user}:#{password}@#{host}",
37
+ 'lcd ./',
38
+ "cd #{remote}",
39
+ 'mirror -L --reverse --only-newer --verbose ' + exclude.map { |el|
40
+ '--exclude-glob ' + el
41
+ } * ' '
42
+ ]
43
+
44
+ system 'lftp', '-c', commands * ';'
45
+ end
46
+ end
47
+
48
+ require './config/deploy.rb'
49
+
50
+ Rubko::Deploy.new.deploy!
@@ -1,7 +1,7 @@
1
1
  require 'rubko/app'
2
2
 
3
3
  class Rubko
4
- VERSION = '0.1'
4
+ VERSION = '0.2'
5
5
 
6
6
  def initialize(shared = {})
7
7
  @shared = shared
@@ -14,7 +14,7 @@ class Rubko::App
14
14
  @finalizers = []
15
15
 
16
16
  @env = env
17
- params = Rack::Utils.parse_nested_query @env['rack.input'].read
17
+ params = Rack::Utils.parse_nested_query env['rack.input'].read
18
18
  @params = Hash[ params.map { |k, v|
19
19
  [ k.to_sym, v ]
20
20
  } ]
@@ -31,49 +31,80 @@ class Rubko::App
31
31
  end
32
32
 
33
33
  def request(name = :welcome, action = nil, *path)
34
- controller = loadController(name) || loadController(:error404)
34
+ @controller = loadController(name) || loadController(:error404)
35
35
 
36
36
  calls = [ action ? "_#{action}" : 'index' ]
37
37
  calls << calls.first + '_' + url.method
38
38
 
39
39
  calls.map! { |call|
40
- if controller.respond_to? call
41
- @body = controller.__send__ call, *path
40
+ if @controller.respond_to? call
41
+ @body = @controller.__send__ call, *path
42
42
  true
43
43
  end
44
44
  }
45
45
  if calls.compact.empty?
46
- @body = controller.other action, *path
46
+ @body = @controller.other action, *path
47
47
  end
48
48
 
49
49
  # finalize request
50
50
  finalizers.reverse_each(&:finalize)
51
- @headers['Content-Type'] = "#{mime}; charset=utf-8" unless @status == 304
51
+ prepareBody!
52
+ prepareHeaders!
52
53
 
53
- # make sure body responds to :each
54
- @body = @body.to_s if Integer === @body
55
- @body = [@body] if String === @body
56
- @body = [] unless @body.respond_to? :each
54
+ [status, headers, body]
55
+ end
56
+
57
+ def production?
58
+ ENV['RACK_ENV'] == 'production'
59
+ end
60
+
61
+ private
62
+
63
+ def prepareBody!
64
+ # if object is a Hash, return JSON
65
+ if Hash === body
66
+ @mime = 'application/json'
67
+ @body = if production?
68
+ body.to_json
69
+ else
70
+ JSON.pretty_generate body, indent: "\t"
71
+ end
72
+ end
73
+
74
+ # make sure body responds to #each
75
+ @body = body.to_s if Integer === body
76
+ @body = [body] if String === body
77
+ @body = [] unless body.respond_to? :each
78
+ end
79
+
80
+ def prepareHeaders!
81
+ # apply mime type header
82
+ unless status == 304
83
+ headers['Content-Type'] = "#{mime}; charset=utf-8"
84
+ end
57
85
 
58
86
  # compress
59
- if controller.compressible?
87
+ if @controller.compressible?
60
88
  headers['Content-Encoding'] = 'gzip'
61
- @body = Rubko::Asset::GzipStream.new @body
89
+ @body = Rubko::Asset::GzipStream.new body
62
90
  end
63
91
 
64
92
  # add Content-Length header
65
- if @body.respond_to? :bytesize
66
- headers['Content-Length'] = @body.bytesize.to_s
67
- elsif Array === @body
68
- headers['Content-Length'] = @body.reduce(0) { |sum, x|
93
+ headers['Content-Length'] = if body.respond_to? :bytesize
94
+ body.bytesize
95
+ elsif Array === body
96
+ body.reduce(0) { |sum, x|
69
97
  sum + x.bytesize
70
- }.to_s
98
+ }
71
99
  end
72
100
 
73
- [@status, @headers, @body]
74
- end
75
-
76
- def production?
77
- ENV['RACK_ENV'] == 'production'
101
+ # rack requires strings as values
102
+ headers.each { |k, v|
103
+ if v.nil?
104
+ headers.delete k
105
+ elsif not String === v
106
+ headers[k] = v.to_s
107
+ end
108
+ }
78
109
  end
79
110
  end
@@ -24,9 +24,9 @@ class Rubko::Asset < Rubko::Controller
24
24
  private :hit, :cache, :miss
25
25
 
26
26
  def compressible?
27
- super && @mime != 'application/octet-stream' &&
27
+ super && mime != 'application/octet-stream' &&
28
28
  ['application', 'text'].any? { |type|
29
- @mime.start_with? type+'/'
29
+ mime.start_with? type+'/'
30
30
  }
31
31
  end
32
32
 
@@ -43,10 +43,10 @@ class Rubko::Asset < Rubko::Controller
43
43
  end
44
44
 
45
45
  path.shift if path[0] =~ /^\d*$/
46
- path = "#{@dir}/#{path * '/'}"
46
+ path = "#{dir}/#{path * '/'}"
47
47
  @mime = Rack::Mime.mime_type File.extname(path)
48
48
  if File.file? path
49
- self.mime = @mime
49
+ self.mime = mime
50
50
  headers['Cache-Control'] = 'public'
51
51
  headers['Vary'] = 'Accept-Encoding'
52
52
 
@@ -55,7 +55,7 @@ class Rubko::Asset < Rubko::Controller
55
55
  headers['Last-Modified'] = @modified.httpdate
56
56
  headers['Expires'] = (DateTime.now >> 12).httpdate
57
57
 
58
- if @modified.to_i <= since
58
+ if modified.to_i <= since
59
59
  cache( *path )
60
60
  self.status = 304
61
61
  ''
@@ -5,7 +5,7 @@ class Rubko
5
5
  module Base
6
6
  def initialize(parent = nil)
7
7
  @parent = parent
8
- finalizers << self if @parent
8
+ finalizers << self if parent
9
9
  @plugins = {}
10
10
  puts "#{self.class} initialized." unless production?
11
11
  end
@@ -14,9 +14,9 @@ class DbPlugin < Rubko::Plugin
14
14
  def handle
15
15
  unless @handle
16
16
  config if @handle.nil?
17
- if @pool
18
- @sig = [@host, @port, @user, @password, @db]
19
- @handle = ( @pool[:db, *@sig] ||= [] ).pop
17
+ if pool
18
+ @sig = [host, port, user, password, db]
19
+ @handle = ( pool[:db, *@sig] ||= [] ).pop
20
20
  end
21
21
  @handle = connect unless @handle
22
22
  end
@@ -27,20 +27,20 @@ class DbPlugin < Rubko::Plugin
27
27
  attr_reader :affectedRows
28
28
 
29
29
  def connect
30
- PG.connect host: @host, port: @post, user: @user, password: @password, dbname: @db
30
+ PG.connect host: host, port: port, user: user, password: password, dbname: db
31
31
  end
32
32
 
33
33
  def release
34
34
  return true unless @handle
35
- if @pool && handle.transaction_status == 0
36
- @pool[:db, *@sig].push @handle
35
+ if pool && handle.transaction_status == 0
36
+ pool[:db, *@sig].push @handle
37
37
  @handle = false
38
38
  return true
39
39
  end
40
40
  end
41
41
 
42
42
  def poolSize
43
- @pool.keys(:db, *@sig).size
43
+ pool.keys(:db, *@sig).size
44
44
  end
45
45
 
46
46
  # PostgreSQL array OIDs and coresponding data type
@@ -330,7 +330,7 @@ class DbPlugin < Rubko::Plugin
330
330
  yield
331
331
  raw 'COMMIT' if inTransaction
332
332
  rescue => e
333
- puts e
333
+ p e
334
334
  puts e.backtrace
335
335
  rollback
336
336
  puts 'Transaction rolled back.'
@@ -31,7 +31,7 @@ class FacebookPlugin < Rubko::Plugin
31
31
  })
32
32
  @token = parse( httpGet url )['access_token']
33
33
 
34
- jsonParse httpGet build 'https://graph.facebook.com/me', access_token: @token
34
+ jsonParse httpGet build 'https://graph.facebook.com/me', access_token: token
35
35
  end
36
36
 
37
37
  private
@@ -24,7 +24,7 @@ class SessionPlugin < Rubko::Plugin
24
24
 
25
25
  if @id
26
26
  if time = storage[name, @id]
27
- destroy if Time.now - time > @timeout
27
+ destroy if Time.now - time > timeout
28
28
  end
29
29
  storage[name, @id] = Time.new
30
30
  end
@@ -10,8 +10,8 @@ class UrlPlugin < Rubko::Plugin
10
10
  end
11
11
 
12
12
  def path=(path)
13
- len = path.start_with?(@base) ? @base.length : 1
14
- @path = URI.unescape(path)[len..-1].chomp(@ending).split '/', -1
13
+ len = path.start_with?(base) ? base.length : 1
14
+ @path = URI.unescape(path)[len..-1].chomp(ending).split '/', -1
15
15
  @newPath = nil
16
16
 
17
17
  @protocol = env['rack.url_scheme'] + '://'
@@ -22,7 +22,7 @@ class UrlPlugin < Rubko::Plugin
22
22
 
23
23
  def newPath
24
24
  unless @newPath
25
- @newPath = @path * '/'
25
+ @newPath = path * '/'
26
26
  config
27
27
  @newPath = @newPath.split '/', -1
28
28
  end
@@ -47,14 +47,14 @@ class UrlPlugin < Rubko::Plugin
47
47
  def generate(*path)
48
48
  path.compact!
49
49
  path.map! { |seg|
50
- seg = @path[seg] if seg.kind_of? Integer
50
+ seg = path[seg] if seg.kind_of? Integer
51
51
  URI.escape seg
52
52
  }
53
- (@protocol+@host if @fullPath).to_s + @base + path.join('/')
53
+ (protocol+host if fullPath).to_s + base + path.join('/')
54
54
  end
55
55
 
56
56
  def link(*path)
57
- generate(*path) + (@ending unless path.empty?).to_s
57
+ generate(*path) + (ending unless path.empty?).to_s
58
58
  end
59
59
 
60
60
  def linkSlug(*path)
@@ -64,7 +64,7 @@ class UrlPlugin < Rubko::Plugin
64
64
  def file(*path)
65
65
  name = 'public/' + path.join('/')
66
66
  time = File.mtime(name).to_i / 3 % 1000000 if File.exists? name
67
- generate @fileBase, (time.to_s if @fileTime), *path
67
+ generate fileBase, (time.to_s if fileTime), *path
68
68
  end
69
69
 
70
70
  def redirect(*path)
@@ -79,11 +79,11 @@ class UrlPlugin < Rubko::Plugin
79
79
  end
80
80
 
81
81
  def refresh
82
- redirect(*@path)
82
+ redirect(*path)
83
83
  end
84
84
 
85
85
  def forceSSL
86
- if @protocol != 'https://'
86
+ if protocol != 'https://'
87
87
  @protocol, @fullPath = 'https://', true
88
88
  refresh
89
89
  end
@@ -0,0 +1,7 @@
1
+ class Rubko::Deploy
2
+ def config
3
+ @host = 'valat.si:54321'
4
+ @user = 'root'
5
+ # @password = ''
6
+ end
7
+ end
@@ -43,7 +43,7 @@
43
43
  if (translation) {
44
44
  var temp=str.replace(value, translation);
45
45
  if (value[0].toLowerCase()===value[0])
46
- return temp[0].toLowerCase()+temp.slice(1)
46
+ return temp[0].toLowerCase()+temp.slice(1);
47
47
  return temp[0].toUpperCase()+temp.slice(1);
48
48
  }
49
49
  $.each($.translate.dictionary[module][language].regex, function(key, val) {
@@ -74,13 +74,14 @@
74
74
  language = language || $.translate.language;
75
75
  $.translate.textNodes(this).each(function() {
76
76
  $(this).untranslate(true);
77
- if ($(this).data('translateO') || $.translate.clear($.translate.get(this))) {
78
- if (!$(this).data('translateO'))
79
- $(this).data('translateO', $.translate.get(this));
80
- var translation = $(this).data('translateO');
81
- if (language === $.translate.original || (translation = $.translate.lookup($(this).data('translateO'), module, language)) ) {
77
+ if (this.trO || $.translate.clear($.translate.get(this))) {
78
+ if (!this.trO)
79
+ this.trO = $.translate.get(this);
80
+ var translation = this.trO;
81
+ if (language === $.translate.original || (translation = $.translate.lookup(this.trO, module, language)) ) {
82
82
  $.translate.set(this, translation);
83
- $(this).data('translateM', module).data('translateL', language);
83
+ this.trM = module;
84
+ this.trL = language;
84
85
  } else $(this).untranslate(true);
85
86
  }
86
87
  });
@@ -89,13 +90,14 @@
89
90
 
90
91
  $.fn.retranslate = function(module_, language_) {
91
92
  $.translate.textNodes(this).each(function() {
92
- if ($(this).data('translateO')) {
93
- var module = module_ || $(this).data('translateM');
94
- var language = language_ || $(this).data('translateL');
95
- var translation = $(this).data('translateO');
96
- if (language === $.translate.original || (translation = $.translate.lookup($(this).data('translateO'), module, language)) ) {
93
+ if (this.trO) {
94
+ var module = module_ || this.trM;
95
+ var language = language_ || this.trL;
96
+ var translation = this.trO;
97
+ if (language === $.translate.original || (translation = $.translate.lookup(this.trO, module, language)) ) {
97
98
  $.translate.set(this, translation);
98
- $(this).data('translateM', module).data('translateL', language);
99
+ this.trM = module;
100
+ this.trL = language;
99
101
  }
100
102
  }
101
103
  });
@@ -104,9 +106,11 @@
104
106
 
105
107
  $.fn.untranslate = function(undo) {
106
108
  $.translate.textNodes(this).each(function() {
107
- if (undo && $(this).data('translateO'))
108
- $.translate.set(this, $(this).data('translateO'));
109
- $(this).removeData();
109
+ if (undo && this.trO)
110
+ $.translate.set(this, this.trO);
111
+ delete this.trM;
112
+ delete this.trL;
113
+ delete this.trO;
110
114
  });
111
115
  };
112
116
  //})();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubko
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rok Kralj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2013-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -59,6 +59,7 @@ files:
59
59
  - stamp/.gitignore
60
60
  - stamp/config.ru
61
61
  - stamp/config/db.rb
62
+ - stamp/config/deploy.rb
62
63
  - stamp/config/facebook.rb
63
64
  - stamp/config/session.rb
64
65
  - stamp/config/url.rb
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  version: '0'
94
95
  requirements: []
95
96
  rubyforge_project:
96
- rubygems_version: 2.0.3
97
+ rubygems_version: 2.0.14
97
98
  signing_key:
98
99
  specification_version: 4
99
100
  summary: Web framework