frontkit-rails 0.0.3 → 0.0.4

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.
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
 
19
19
  # specify any dependencies here; for example:
20
20
  s.add_development_dependency 'rspec'
21
- s.add_development_dependency 'execjs'
22
21
  s.add_runtime_dependency 'railties', '>= 3.1.0'
22
+ s.add_runtime_dependency 'activesupport', '>= 3.1.0'
23
23
  s.add_runtime_dependency 'sprockets'
24
24
  s.add_runtime_dependency 'multi_json'
25
25
  end
@@ -2,4 +2,4 @@ require 'frontkit-rails/engine' if defined?(Rails)
2
2
  require 'frontkit-rails/version'
3
3
 
4
4
  module FrontKit
5
- end
5
+ end
@@ -1,7 +1,8 @@
1
+ require 'active_support'
1
2
  require 'frontkit-rails/serializer'
2
3
  require 'frontkit-rails/state'
3
4
  require 'frontkit-rails/meta_container'
4
- require 'active_support/concern'
5
+
5
6
 
6
7
  module FrontKit
7
8
  module Base
@@ -1,10 +1,11 @@
1
1
  require 'base64'
2
2
  require 'multi_json'
3
+ require 'active_support/core_ext/module/delegation'
3
4
 
4
5
  module FrontKit
5
6
  class Serializer
6
7
  def encode(hash)
7
- Base64.encode64(MultiJson.encode(hash)).strip
8
+ Base64.encode64(MultiJson.encode(hash)).gsub(/\s+/, '')
8
9
  end
9
10
 
10
11
  def decode(str)
@@ -1,6 +1,6 @@
1
1
  require 'active_support/hash_with_indifferent_access'
2
2
 
3
3
  module FrontKit
4
- class State < ActiveSupport::HashWithIndifferentAccess
4
+ class State < ::ActiveSupport::HashWithIndifferentAccess
5
5
  end
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module FrontKit
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe FrontKit::Serializer do
6
+
7
+ STATE_HASH = {
8
+ jp: '岩国に空港ができるの? 採算取れるのかな?',
9
+ ru: 'тестовая строка с кириллическими символами',
10
+ symbols: '!@#$%^&*()~{}|":<>?'
11
+ }.stringify_keys
12
+
13
+ it 'serializes hashes to base 64 string' do
14
+ FrontKit.encode(STATE_HASH).should == 'eyJqcCI6IuWyqeWbveOBq+epuua4r+OBjOOBp+OBjeOCi+OBru+8nyDmjqHnrpflj5bjgozjgovjga7jgYvjgarvvJ8iLCJydSI6ItGC0LXRgdGC0L7QstCw0Y8g0YHRgtGA0L7QutCwINGBINC60LjRgNC40LvQu9C40YfQtdGB0LrQuNC80Lgg0YHQuNC80LLQvtC70LDQvNC4Iiwic3ltYm9scyI6IiFAIyQlXiYqKCl+e318XCI6PD4/In0='
15
+ end
16
+
17
+ it 'unserializes base 64 string back to hashes' do
18
+ FrontKit.decode('eyJqcCI6IuWyqeWbveOBq+epuua4r+OBjOOBp+OBjeOCi+OBru+8nyDmjqHnrpflj5bjgozjgovjga7jgYvjgarvvJ8iLCJydSI6ItGC0LXRgdGC0L7QstCw0Y8g0YHRgtGA0L7QutCwINGBINC60LjRgNC40LvQu9C40YfQtdGB0LrQuNC80Lgg0YHQuNC80LLQvtC70LDQvNC4Iiwic3ltYm9scyI6IiFAIyQlXiYqKCl+e318XCI6PD4/In0=').should == STATE_HASH
19
+ end
20
+
21
+ it 'garantees that serializing/unserializing generates the same value' do
22
+ FrontKit.decode(FrontKit.encode(STATE_HASH)).should == STATE_HASH
23
+ end
24
+
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require File.expand_path '../../lib/frontkit-rails/base', __FILE__
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.filter_run focus: true
7
+ config.run_all_when_everything_filtered = true
8
+ end
@@ -1,3 +1,5 @@
1
+ strFromCharCode = String.fromCharCode
2
+
1
3
  this.Unicode =
2
4
  unpack: (utfstring) ->
3
5
  utfstring = utfstring.replace /\r\n/g, "\n"
@@ -7,14 +9,14 @@ this.Unicode =
7
9
  c = utfstring.charCodeAt(i)
8
10
 
9
11
  if c < 128
10
- string += String.fromCharCode(c)
12
+ string += strFromCharCode(c)
11
13
  else if (c > 127) && (c < 2048)
12
- string += String.fromCharCode((c >> 6) | 192)
13
- string += String.fromCharCode((c & 63) | 128)
14
+ string += strFromCharCode((c >> 6) | 192)
15
+ string += strFromCharCode((c & 63) | 128)
14
16
  else
15
- string += String.fromCharCode((c >> 12) | 224)
16
- string += String.fromCharCode(((c >> 6) & 63) | 128)
17
- string += String.fromCharCode((c & 63) | 128)
17
+ string += strFromCharCode((c >> 12) | 224)
18
+ string += strFromCharCode(((c >> 6) & 63) | 128)
19
+ string += strFromCharCode((c & 63) | 128)
18
20
 
19
21
  string
20
22
 
@@ -27,16 +29,16 @@ this.Unicode =
27
29
  c = string.charCodeAt(i)
28
30
 
29
31
  if c < 128
30
- utfstring += String.fromCharCode(c)
32
+ utfstring += strFromCharCode(c)
31
33
  i++
32
34
  else if (c > 191) && (c < 224)
33
35
  c2 = string.charCodeAt(i+1)
34
- utfstring += String.fromCharCode(((c & 31) << 6) | (c2 & 63))
36
+ utfstring += strFromCharCode(((c & 31) << 6) | (c2 & 63))
35
37
  i += 2
36
38
  else
37
39
  c2 = string.charCodeAt(i+1)
38
40
  c3 = string.charCodeAt(i+2)
39
- utfstring += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))
41
+ utfstring += strFromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63))
40
42
  i += 3
41
43
 
42
44
  utfstring
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontkit-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-02 00:00:00.000000000 Z
12
+ date: 2012-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70348169035560 !ruby/object:Gem::Requirement
16
+ requirement: &70292057529100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70348169035560
24
+ version_requirements: *70292057529100
25
25
  - !ruby/object:Gem::Dependency
26
- name: execjs
27
- requirement: &70348169035140 !ruby/object:Gem::Requirement
26
+ name: railties
27
+ requirement: &70292057527640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
32
+ version: 3.1.0
33
+ type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70348169035140
35
+ version_requirements: *70292057527640
36
36
  - !ruby/object:Gem::Dependency
37
- name: railties
38
- requirement: &70348169034620 !ruby/object:Gem::Requirement
37
+ name: activesupport
38
+ requirement: &70292057527120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70348169034620
46
+ version_requirements: *70292057527120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sprockets
49
- requirement: &70348169034040 !ruby/object:Gem::Requirement
49
+ requirement: &70292057526740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70348169034040
57
+ version_requirements: *70292057526740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70348169033420 !ruby/object:Gem::Requirement
60
+ requirement: &70292057526120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70348169033420
68
+ version_requirements: *70292057526120
69
69
  description: Bunch of rails/js helpers packed in asset pipeline friendly engine.
70
70
  email:
71
71
  - rwz@duckroll.ru
@@ -85,6 +85,8 @@ files:
85
85
  - lib/frontkit-rails/serializer.rb
86
86
  - lib/frontkit-rails/state.rb
87
87
  - lib/frontkit-rails/version.rb
88
+ - spec/frontkit-rails/serializer_spec.rb
89
+ - spec/spec_helper.rb
88
90
  - vendor/assets/javascripts/base64/base64.js.coffee
89
91
  - vendor/assets/javascripts/base64/index.js
90
92
  - vendor/assets/javascripts/base64/unicode.js.coffee
@@ -113,8 +115,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  version: '0'
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 1.8.10
118
+ rubygems_version: 1.8.11
117
119
  signing_key:
118
120
  specification_version: 3
119
121
  summary: Bunch of rails/js helpers.
120
- test_files: []
122
+ test_files:
123
+ - spec/frontkit-rails/serializer_spec.rb
124
+ - spec/spec_helper.rb