Module: AtlasRender

Defined in:
lib/atlas_on_rails/render.rb

Defined Under Namespace

Classes: MapRenderError, NoTitleError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/atlas_on_rails/render.rb', line 7

def self.included(base)
  base.extend(self)
  base.class_eval do
    alias_method_chain :render_partial_collection, :map
    alias_method_chain :javascript_include_tag, :map
    alias_method_chain :render, :map
  end
end

Instance Method Details

#javascript_include_tag_with_map(*sources) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/atlas_on_rails/render.rb', line 16

def javascript_include_tag_with_map(*sources)
  javascript_content = []
  sources_not_map = []
  sources.each{|atlasmap|
    if atlasmap.class==AtlasMap
      javascript_content << atlasmap.header
      javascript_content << atlasmap.javascript(self)
    else
      sources_not_map << atlasmap
    end
  }
  sources = sources_not_map
  javascript_content << javascript_include_tag_without_map(*sources)
  javascript_content
end

#render_partial_collection_with_map(partial_name, collection, partial_spacer_template = nil, local_assigns = nil) ⇒ Object

:nodoc:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/atlas_on_rails/render.rb', line 44

def render_partial_collection_with_map(partial_name, collection, partial_spacer_template = nil, local_assigns = nil) #:nodoc:
  if partial_spacer_template=="AtlasMapSpacer"
    collection_of_partials = Array.new
    counter_name = partial_counter_name(partial_name)
    local_assigns = local_assigns ? local_assigns.clone : {}
    collection.each_with_index do |element, counter|
      local_assigns[counter_name] = counter
      raise NoTitleError, "The collection provided has no short_title attribute, create a new method on the model if required so we know what text to place on the tab." unless element.attributes.include?("short_title") || element.methods.include?("short_title")
      collection_of_partials.push("new GInfoWindowTab('"+escape_javascript(element.short_title)+"','"+ escape_javascript(render_partial(partial_name, element, local_assigns)) +"')")
    end
    return " " if collection_of_partials.empty?
    collection_of_partials.join(",")
  else
    render_partial_collection_without_map(partial_name, collection, partial_spacer_template, local_assigns)
  end
end

#render_with_map(options = {}, old_local_assigns = {}, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/atlas_on_rails/render.rb', line 32

def render_with_map(options = {}, old_local_assigns = {}, &block)
  if options[:map]
    if options[:map].class==AtlasMap
      return @map.html(self)
    else
      raise MapRenderError, "The map provided is not a valid AtlasMap object"
    end
  else
    render_without_map(options, old_local_assigns)
  end
end