Skip to content

Commit

Permalink
refactory of javascripts generation incompatible with metainfo commen…
Browse files Browse the repository at this point in the history
…ts. Fix for HTML comments included as javascript source
  • Loading branch information
ddnexus committed Apr 28, 2011
1 parent 9b411dc commit 08e5475
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
8 changes: 0 additions & 8 deletions dryml/lib/dryml/template_environment.rb
Expand Up @@ -527,14 +527,6 @@ def merge_parameter_hashes(given_parameters, overriding_parameters)
end




def part_contexts_javascripts
storage = part_contexts_storage
storage.blank? ? "" : "<script type=\"text/javascript\">\n#{storage}</script>\n"
end


def part_contexts_storage
PartContext.client_side_storage(@_part_contexts, session)
end
Expand Down
47 changes: 29 additions & 18 deletions hobo/lib/hobo/rapid/taglibs/rapid_core.dryml
Expand Up @@ -159,24 +159,35 @@ Provides a short hand way of displaying images in public/images


<!-- Renders some standard JavaScript code that various features of the Rapid library rely on. This tag would typicallu be called from your `<page>` tag. The default Rapid pages include this already. -->
<def tag="hobo-rapid-javascripts"><%=
res = 'var hoboParts = {};'
# FIXME: This should interrogate the model-router - not the models
unless Hobo::Model.all_models.empty?
# Tell JS code how to pluralize names, unless they follow the simple rule
names = Hobo::Model.all_models.map do |m|
m = m.name.underscore
"#{m}: '#{m.pluralize}'" unless m.pluralize == m + 's'
end.compact
res << "var pluralisations = {#{names * ', '}}; "
end
base = [base_url, subsite].compact.join("/")
res << "urlBase = '#{base}'; hoboPagePath = '#{request.fullpath}'"
if protect_against_forgery?
res << "; formAuthToken = { name: '#{request_forgery_protection_token}', value: '#{form_authenticity_token}' }"
end
res
%></def>
<def tag="hobo-rapid-javascripts">
<script type="text/javascript" param="default"><%=
res = 'var hoboParts = {};'
# FIXME: This should interrogate the model-router - not the models
unless Hobo::Model.all_models.empty?
# Tell JS code how to pluralize names, unless they follow the simple rule
names = Hobo::Model.all_models.map do |m|
m = m.name.underscore
"#{m}: '#{m.pluralize}'" unless m.pluralize == m + 's'
end.compact
res << "var pluralisations = {#{names * ', '}}; "
end
base = [base_url, subsite].compact.join("/")
res << "urlBase = '#{base}'; hoboPagePath = '#{request.fullpath}'"
if protect_against_forgery?
res << "; formAuthToken = { name: '#{request_forgery_protection_token}', value: '#{form_authenticity_token}' }"
end
res
%></script>
</def>


<def tag="part-contexts-javascripts">
<% unless (storage = part_contexts_storage).blank? %>
<script type="text/javascript"><%=
storage
%></script>
<% end %>
</def>

<!-- Renders the name of the current context using a variety of methods.

Expand Down
6 changes: 3 additions & 3 deletions hobo/lib/hobo/rapid/taglibs/rapid_pages.dryml
Expand Up @@ -55,10 +55,10 @@ The easiest way to see what this tag does is to look at the source.

<!-- Renderes dynamically generated JavaScript required by `hobo-rapid.js`, including the information required to perform automatic part updates -->
<def tag="page-scripts">
<script type="text/javascript" param="default">
<do param="default">
<hobo-rapid-javascripts/>
<part-contexts-storage/>
</script>
<part-contexts-javascripts/>
</do>
</def>


Expand Down

2 comments on commit 08e5475

@bryanlarsen
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. Glad you got it in before 1.3.0, this will affect anybody who redefines page-scripts or calls hobo-rapid-javascripts or part-contexts-storage themselves. I wonder if we should rename the tags so that such users get immediate errors rather than messed up HTML?

@ddnexus
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patches welcome :-)

Please sign in to comment.