jsonr 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/Rakefile +16 -15
- data/VERSION +1 -1
- data/init.rb +1 -0
- data/jsonr.gemspec +62 -0
- data/lib/jsonr.rb +8 -1
- data/lib/jsonr/generator.rb +10 -2
- data/lib/jsonr/template_handler.rb +2 -2
- data/rails/init.rb +1 -4
- data/spec/jsonr_spec.rb +93 -3
- data/spec/spec_helper.rb +2 -1
- metadata +21 -2
data/LICENSE
CHANGED
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/jzajpt/jsonr"
|
12
12
|
gem.authors = ["Jiri Zajpt"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_dependency('activesupport', '>= 3.0.0.beta4')
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
@@ -18,21 +19,21 @@ rescue LoadError
|
|
18
19
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
36
37
|
|
37
38
|
require 'rake/rdoctask'
|
38
39
|
Rake::RDocTask.new do |rdoc|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'rails', 'init')
|
data/jsonr.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{jsonr}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jiri Zajpt"]
|
12
|
+
s.date = %q{2010-07-16}
|
13
|
+
s.description = %q{A replacement for RJS templates using JSON.}
|
14
|
+
s.email = %q{jzajpt@blueberryapps.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"init.rb",
|
27
|
+
"jsonr.gemspec",
|
28
|
+
"lib/jsonr.rb",
|
29
|
+
"lib/jsonr/generator.rb",
|
30
|
+
"lib/jsonr/template_handler.rb",
|
31
|
+
"rails/init.rb",
|
32
|
+
"spec/jsonr_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/jzajpt/jsonr}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{A replacement for RJS templates using JSON.}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/jsonr_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/jsonr.rb
CHANGED
@@ -1,2 +1,9 @@
|
|
1
1
|
require 'jsonr/generator'
|
2
|
-
|
2
|
+
|
3
|
+
if defined?(::ActionView)
|
4
|
+
require 'jsonr/template_handler'
|
5
|
+
|
6
|
+
# Hook into ActionView, register jsonr extension.
|
7
|
+
::ActionView::Template.register_template_handler :jsonr, Jsonr::TemplateHandler
|
8
|
+
end
|
9
|
+
|
data/lib/jsonr/generator.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Jsonr
|
2
2
|
|
3
|
+
require 'active_support/ordered_hash'
|
4
|
+
require 'active_support/json'
|
5
|
+
|
3
6
|
module Jsonr
|
4
7
|
|
5
8
|
class Generator
|
@@ -11,7 +14,7 @@ module Jsonr
|
|
11
14
|
|
12
15
|
# Convert to a JSON string representation.
|
13
16
|
def to_s
|
14
|
-
@commands
|
17
|
+
ActiveSupport::JSON.encode(@commands)
|
15
18
|
end
|
16
19
|
|
17
20
|
# Replaces a content of an element with given selector with given value.
|
@@ -93,7 +96,7 @@ module Jsonr
|
|
93
96
|
# page.flash :notice, "A person detail's were updated."
|
94
97
|
#
|
95
98
|
def flash(severity, message)
|
96
|
-
@commands[:flash] ||=
|
99
|
+
@commands[:flash] ||= ActiveSupport::OrderedHash.new
|
97
100
|
@commands[:flash][severity] = message
|
98
101
|
end
|
99
102
|
|
@@ -144,6 +147,11 @@ module Jsonr
|
|
144
147
|
@commands[:remove].push *selectors
|
145
148
|
end
|
146
149
|
|
150
|
+
# Sets given +key+ to a given +value+. Useful for passing custom objects.
|
151
|
+
#
|
152
|
+
# Example:
|
153
|
+
#
|
154
|
+
# page.data :person, @person
|
147
155
|
def data(key, value)
|
148
156
|
@commands[key] = value
|
149
157
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Jsonr
|
2
2
|
|
3
|
-
class TemplateHandler < ActionView::TemplateHandler
|
3
|
+
class TemplateHandler < ::ActionView::TemplateHandler
|
4
4
|
|
5
|
-
include ActionView::TemplateHandlers::Compilable
|
5
|
+
include ::ActionView::TemplateHandlers::Compilable
|
6
6
|
|
7
7
|
def compile(template)
|
8
8
|
"@template_format = :html;" +
|
data/rails/init.rb
CHANGED
data/spec/jsonr_spec.rb
CHANGED
@@ -1,7 +1,97 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "Jsonr" do
|
4
|
-
|
5
|
-
|
3
|
+
describe "Jsonr::Generator" do
|
4
|
+
|
5
|
+
context "an empty generator instance" do
|
6
|
+
|
7
|
+
it "converts to empty json object" do
|
8
|
+
generator = Jsonr::Generator.new
|
9
|
+
generator.to_s.should == '{}'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#redirect_to" do
|
15
|
+
|
16
|
+
it "converts to json object with redirect_to key" do
|
17
|
+
generator = Jsonr::Generator.new do |page|
|
18
|
+
page.redirect_to '/new/url'
|
19
|
+
end
|
20
|
+
|
21
|
+
generator.to_s.should == %Q|{"redirect_to":"/new/url"}|
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#flash" do
|
27
|
+
|
28
|
+
it "converts to json object with flash key" do
|
29
|
+
generator = Jsonr::Generator.new do |page|
|
30
|
+
page.flash :notice, "it's done!"
|
31
|
+
end
|
32
|
+
|
33
|
+
generator.to_s.should == %Q|{"flash":{"notice":"it's done!"}}|
|
34
|
+
end
|
35
|
+
|
36
|
+
it "converts all flashes" do
|
37
|
+
generator = Jsonr::Generator.new do |page|
|
38
|
+
page.flash :notice, "it's done!"
|
39
|
+
page.flash :error, "no it's not!"
|
40
|
+
end
|
41
|
+
|
42
|
+
generator.to_s.should == %Q|{"flash":{"notice":"it's done!","error":"no it's not!"}}|
|
43
|
+
end
|
44
|
+
|
6
45
|
end
|
46
|
+
|
47
|
+
%w(hide show toggle remove).each do |cmd|
|
48
|
+
|
49
|
+
context "##{cmd}" do
|
50
|
+
|
51
|
+
it "convert to json object with hide key" do
|
52
|
+
generator = Jsonr::Generator.new do |page|
|
53
|
+
page.send cmd, '#selector1'
|
54
|
+
end
|
55
|
+
|
56
|
+
generator.to_s.should == %Q|{"#{cmd}":["#selector1"]}|
|
57
|
+
end
|
58
|
+
|
59
|
+
it "convert all given selectors" do
|
60
|
+
generator = Jsonr::Generator.new do |page|
|
61
|
+
page.send cmd, '#selector1', '.selector2'
|
62
|
+
end
|
63
|
+
|
64
|
+
generator.to_s.should == %Q|{"#{cmd}":["#selector1",".selector2"]}|
|
65
|
+
end
|
66
|
+
|
67
|
+
it "convert all given selectors when called more times" do
|
68
|
+
generator = Jsonr::Generator.new do |page|
|
69
|
+
page.send cmd, '#selector1'
|
70
|
+
page.send cmd, '.selector2'
|
71
|
+
end
|
72
|
+
|
73
|
+
generator.to_s.should == %Q|{"#{cmd}":["#selector1",".selector2"]}|
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
%w(replace append prepend replace_with insert_before).each do |cmd|
|
82
|
+
|
83
|
+
context "##{cmd}" do
|
84
|
+
|
85
|
+
it "convert to json object with #{cmd} key" do
|
86
|
+
generator = Jsonr::Generator.new do |page|
|
87
|
+
page.send(cmd, "#selector1", "content")
|
88
|
+
end
|
89
|
+
|
90
|
+
generator.to_s.should == %Q|{"#{cmd}":{"#selector1":"content"}}|
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
7
97
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jiri Zajpt
|
@@ -34,6 +34,23 @@ dependencies:
|
|
34
34
|
version: 1.2.9
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: -1848230024
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
- beta4
|
51
|
+
version: 3.0.0.beta4
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
37
54
|
description: A replacement for RJS templates using JSON.
|
38
55
|
email: jzajpt@blueberryapps.com
|
39
56
|
executables: []
|
@@ -50,6 +67,8 @@ files:
|
|
50
67
|
- README.rdoc
|
51
68
|
- Rakefile
|
52
69
|
- VERSION
|
70
|
+
- init.rb
|
71
|
+
- jsonr.gemspec
|
53
72
|
- lib/jsonr.rb
|
54
73
|
- lib/jsonr/generator.rb
|
55
74
|
- lib/jsonr/template_handler.rb
|