Skip to content

Commit

Permalink
added rails 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertech committed Oct 27, 2012
1 parent 8e293e6 commit b35176b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backbone-bootstrapper.gemspec
Expand Up @@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
gem.version = Backbone::Bootstrapper::VERSION
gem.authors = ["Andrew Eberbach"]
gem.email = ["andrew@ebertech.ca"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.description = %q{A helper to bootstrap backbone models and collections}
gem.summary = %q{A helper to bootstrap backbone models and collections}
gem.homepage = ""

gem.files = `git ls-files`.split($/)
Expand Down
21 changes: 14 additions & 7 deletions lib/backbone/bootstrapper/helper.rb
Expand Up @@ -9,22 +9,29 @@ def included(base)
end
end
end

module InstanceMethods
def backbone_bootstraps
@template.javascript_tag do
(@bootstrappers || []).map do |bootstrapper|
with_javascript_tag do
(@bootstrappers || []).map do |bootstrapper|
[bootstrapper.declaration, bootstrapper.initialization].join("\n")
end.join("\n")
end
end

def bootstrap_backbone(key, object, template, type = nil)
@bootstrappers ||= []
@bootstrappers << if object.is_a?(Array)
Bootstrapper::Collection.new(key, object, template, type)
else
Bootstrapper::Model.new(key, object, template, type)
Bootstrapper::Collection.new(key, object, template, type)
else
Bootstrapper::Model.new(key, object, template, type)
end
end

private
def with_javascript_tag(&block)
(@template || view_context).javascript_tag(&block).tap do |r|
return r.html_safe if r.respond_to?(:html_safe)
end
end
end
Expand Down

0 comments on commit b35176b

Please sign in to comment.