mambo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 - 2013 Lawrence Pit
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,32 @@
1
+ # Mambo
2
+
3
+ [![Build Status](https://secure.travis-ci.org/lawrencepit/mambo.png?branch=master)](http://travis-ci.org/lawrencepit/mambo) [![Code Climate](https://codeclimate.com/github/lawrencepit/mambo)](https://codeclimate.com/github/lawrencepit/mambo) [![Gem Version](https://fury-badge.herokuapp.com/rb/mambo.png)](http://badge.fury.io/rb/mambo)
4
+
5
+
6
+ ## Installation and Usage
7
+
8
+ gem install mambo
9
+
10
+ In a view file:
11
+
12
+ # app/views/posts/show.json.mambo
13
+ json[:title] = @post.title
14
+ json[:author] = @post.author.name
15
+
16
+ or:
17
+
18
+ # app/views/posts/show.json.mambo
19
+ json << some_helper_method(@post).to_json
20
+
21
+
22
+ Authors
23
+ ----------
24
+
25
+ [Lawrence Pit](https://github.com/lawrencepit), [@lawrencepit](http://twitter.com/lawrencepit)
26
+ [orslumen](https://github.com/orslumen)
27
+
28
+
29
+ Copyright
30
+ -----------
31
+
32
+ Copyright (c) 2009 - 2013 Lawrence Pit See MIT-LICENSE for details.
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'mambo/version'
3
+ require 'mambo/mambo'
4
+ require 'mambo/mambo_template_handler'
5
+ ::ActionView::Template.register_template_handler(:mambo, ::ActionView::Template::Handlers::MamboTemplateHandler)
@@ -0,0 +1,39 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mambo
3
+ class Mambo < ActiveSupport::BasicObject
4
+
5
+ def method_missing(method, *args, &block)
6
+ if block
7
+ keep = @target
8
+ @target = {}
9
+ block.call(self)
10
+ value = @target
11
+ @target = keep
12
+ else
13
+ value = args.length == 1 ? args.first : args
14
+ end
15
+
16
+ v = @target[method]
17
+ if v.nil?
18
+ @target[method] = value
19
+ elsif v.is_a?(::Array)
20
+ v << value
21
+ else
22
+ @target[method] = [v, value]
23
+ end
24
+ end
25
+
26
+ def <<(value)
27
+ @target = [] if @target.is_a?(::Hash)
28
+ @target << value
29
+ end
30
+
31
+ def initialize ; @target = {} ; end
32
+ def respond_to?(_) ; true ; end
33
+ def to_s ; @target.to_s ; end
34
+ def inspect ; @target.inspect ; end
35
+ def to_json ; @target.to_json ; end
36
+ def nil? ; false ; end
37
+
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding : utf-8 -*-
2
+ if ActionPack::VERSION::STRING =~ /^3\.0/
3
+
4
+ module ActionView
5
+ module Template::Handlers
6
+ class MamboTemplateHandler < Template::Handler
7
+ include Compilable
8
+
9
+ self.default_format = Mime::JSON
10
+
11
+ def compile(template)
12
+ "update_page do |page|;#{template.source}\nend"
13
+ end
14
+
15
+ def default_format
16
+ Mime::JSON
17
+ end
18
+
19
+ def compile(template)
20
+ "json = ::Mambo::Mambo.new;#{template.source};json.to_json;"
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ else
27
+
28
+ module ActionView
29
+ module Template::Handlers
30
+ class MamboTemplateHandler
31
+
32
+ class_attribute :default_format
33
+ self.default_format = Mime::JSON
34
+
35
+ def self.call(template)
36
+ "json = ::Mambo::Mambo.new;" +
37
+ template.source +
38
+ ";json.to_json;"
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ module Mambo
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mambo/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{mambo}
7
+ s.version = Mambo::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Lawrence Pit"]
10
+ s.email = %q{lawrence.pit@gmail.com}
11
+ s.homepage = %q{http://github.com/lawrencepit/mambo}
12
+ s.summary = %q{JSON rendering as a view in Rails}
13
+ s.description = %q{JSON rendering as a view in Rails}
14
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
15
+ s.files = Dir.glob("lib/**/*") + [
16
+ "MIT-LICENSE",
17
+ "README.md",
18
+ "Gemfile",
19
+ "mambo.gemspec"
20
+ ]
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ s.rdoc_options = ["--charset=UTF-8"]
25
+
26
+ s.add_dependency('actionpack', '>= 3.0.0')
27
+
28
+ s.add_development_dependency "rake"
29
+ # s.add_development_dependency "rcov"
30
+ s.add_development_dependency "rspec"
31
+ s.add_development_dependency "rr"
32
+ end
33
+
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mambo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lawrence Pit
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: JSON rendering as a view in Rails
79
+ email: lawrence.pit@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/mambo/mambo.rb
85
+ - lib/mambo/mambo_template_handler.rb
86
+ - lib/mambo/version.rb
87
+ - lib/mambo.rb
88
+ - MIT-LICENSE
89
+ - README.md
90
+ - Gemfile
91
+ - mambo.gemspec
92
+ homepage: http://github.com/lawrencepit/mambo
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.25
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: JSON rendering as a view in Rails
117
+ test_files: []