jsonr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jiri Zajpt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = JsonR
2
+
3
+ A replacement for RJS templates using JSON.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jiri Zajpt. See LICENSE for details.
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "jsonr"
8
+ gem.summary = %Q{A replacement for RJS templates using JSON.}
9
+ gem.description = %Q{A replacement for RJS templates using JSON.}
10
+ gem.email = "jzajpt@blueberryapps.com"
11
+ gem.homepage = "http://github.com/jzajpt/jsonr"
12
+ gem.authors = ["Jiri Zajpt"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ # require 'spec/rake/spectask'
22
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ # spec.libs << 'lib' << 'spec'
24
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ # end
26
+ #
27
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ # spec.libs << 'lib' << 'spec'
29
+ # spec.pattern = 'spec/**/*_spec.rb'
30
+ # spec.rcov = true
31
+ # end
32
+ #
33
+ # task :spec => :check_dependencies
34
+ #
35
+ # task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "jsonr #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'jsonr'
2
+
3
+ # Hook into ActionView, register jsonr extension.
4
+ ActionView::Template.register_template_handler :jsonr, Jsonr::TemplateHandler
@@ -0,0 +1,2 @@
1
+ require 'jsonr/generator'
2
+ require 'jsonr/template_handler'
@@ -0,0 +1,153 @@
1
+ # Jsonr
2
+
3
+ module Jsonr
4
+
5
+ class Generator
6
+
7
+ def initialize(&block)
8
+ @commands = {}
9
+ block.call(self) if block_given?
10
+ end
11
+
12
+ # Convert to a JSON string representation.
13
+ def to_s
14
+ @commands.to_json
15
+ end
16
+
17
+ # Replaces a content of an element with given selector with given value.
18
+ #
19
+ # Example:
20
+ #
21
+ # # Redirect to persons listing.
22
+ # page.replace "#person_1", @person
23
+ #
24
+ def replace(selector, content)
25
+ @commands[:replace] ||= {}
26
+ @commands[:replace][selector] = content
27
+ end
28
+
29
+ # Appends given content to an element with given selector.
30
+ #
31
+ # Example:
32
+ #
33
+ # # Redirect to persons listing.
34
+ # page.append "#persons", @person
35
+ #
36
+ def append(selector, content)
37
+ @commands[:append] ||= {}
38
+ @commands[:append][selector] = content
39
+ end
40
+
41
+ # Prepends given content to an element with given selector.
42
+ #
43
+ # Example:
44
+ #
45
+ # # Redirect to persons listing.
46
+ # page.append "#persons", @person
47
+ #
48
+ def prepend(selector, content)
49
+ @commands[:prepend] ||= {}
50
+ @commands[:prepend][selector] = content
51
+ end
52
+
53
+ # Replaces an element with given selector with given value.
54
+ #
55
+ # Example:
56
+ #
57
+ # # Redirect to persons listing.
58
+ # page.replace_with "#person_1", @person
59
+ #
60
+ def replace_with(selector, content)
61
+ @commands[:replace_with] ||= {}
62
+ @commands[:replace_with][selector] = content
63
+ end
64
+
65
+ # Inserts given content before an element with given selector.
66
+ #
67
+ # Example:
68
+ #
69
+ # # Redirect to persons listing.
70
+ # page.insert_before "#persons", @person
71
+ #
72
+ def insert_before(selector, content)
73
+ @commands[:insert_before] ||= {}
74
+ @commands[:insert_before][selector] = content
75
+ end
76
+
77
+ # Redirects a client to a given url.
78
+ #
79
+ # Example:
80
+ #
81
+ # # Redirect to persons listing.
82
+ # page.redirect_to persons_url
83
+ #
84
+ def redirect_to(url)
85
+ @commands[:redirect_to] = url
86
+ end
87
+
88
+ # Displays a flash notice.
89
+ #
90
+ # Example:
91
+ #
92
+ # # Show a flash message notice
93
+ # page.flash :notice, "A person detail's were updated."
94
+ #
95
+ def flash(severity, message)
96
+ @commands[:flash] ||= {}
97
+ @commands[:flash][severity] = message
98
+ end
99
+
100
+ # Hides elements with given +selectors+.
101
+ #
102
+ # Example:
103
+ #
104
+ # # Hide a few people
105
+ # page.hide '#person_1', '#person_2'
106
+ #
107
+ def hide(*selectors)
108
+ @commands[:hide] ||= []
109
+ @commands[:hide].push *selectors
110
+ end
111
+
112
+ # Shows hidden elements with the given +selectors+.
113
+ #
114
+ # Example:
115
+ #
116
+ # # Show a few people
117
+ # page.show '#person_1', '#person_2'
118
+ #
119
+ def show(*selectors)
120
+ @commands[:show] ||= []
121
+ @commands[:show].push *selectors
122
+ end
123
+
124
+ # Toggles the visibility of the elements with the given +selectors+.
125
+ #
126
+ # Example:
127
+ #
128
+ # # Toggle a few people
129
+ # page.toggle '#person_1', '#person_2'
130
+ #
131
+ def toggle(*selectors)
132
+ @commands[:toggle] ||= []
133
+ @commands[:toggle].push *selectors
134
+ end
135
+
136
+ # Removes elements with the given +selectors+.
137
+ #
138
+ # Example:
139
+ #
140
+ # page.remove '#person_1', '#person_2'
141
+ #
142
+ def remove(*selectors)
143
+ @commands[:remove] ||= []
144
+ @commands[:remove].push *selectors
145
+ end
146
+
147
+ def data(key, value)
148
+ @commands[key] = value
149
+ end
150
+
151
+ end
152
+
153
+ end
@@ -0,0 +1,15 @@
1
+ module Jsonr
2
+
3
+ class TemplateHandler < ActionView::TemplateHandler
4
+
5
+ include ActionView::TemplateHandlers::Compilable
6
+
7
+ def compile(template)
8
+ "@template_format = :html;" +
9
+ "controller.response.content_type ||= Mime::JSON;" +
10
+ "Jsonr::Generator.new{ |page| #{template.source} }.to_s"
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Jsonr" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'jsonr'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsonr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jiri Zajpt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-16 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: A replacement for RJS templates using JSON.
38
+ email: jzajpt@blueberryapps.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - init.rb
54
+ - lib/jsonr.rb
55
+ - lib/jsonr/generator.rb
56
+ - lib/jsonr/template_handler.rb
57
+ - spec/jsonr_spec.rb
58
+ - spec/spec.opts
59
+ - spec/spec_helper.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/jzajpt/jsonr
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A replacement for RJS templates using JSON.
94
+ test_files:
95
+ - spec/jsonr_spec.rb
96
+ - spec/spec_helper.rb