Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Content type helper #1

Merged
merged 1 commit into from

2 participants

@dsci

First - great extension!

Recently I ran into an exception which was thrown because

page_part.page.layout

was nil. I just wrapped this into a helper method which returns a
default content_type ("text/html"):

Remove the content_type inspection of the page part into a
helper method and return a default content_type if page part
hasn't any layout attached.

-- Maybe you are interested in this.

Regards,
Daniel

@dsci dsci Remove content_type inspection into helper_method
Remove the content_type inspection of the page part into a
helper method and return a default content_type if page part
hasn't any layout attached.
197d4a9
@danhigham danhigham merged commit 0a5ab81 into danhigham:master
@danhigham
Owner

Awesome, thanks for this. I have pulled the change in as requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 29, 2011
  1. @dsci

    Remove content_type inspection into helper_method

    dsci authored
    Remove the content_type inspection of the page part into a
    helper method and return a default content_type if page part
    hasn't any layout attached.
This page is out of date. Refresh to see the latest.
View
13 app/helpers/admin/ace_helper.rb
@@ -2,6 +2,19 @@ module Admin::AceHelper
include Admin::NodeHelper
include Admin::ReferencesHelper
+ def content_type_for_page(page_part)
+ default_content_type = "text/html"
+ if page_part.page.nil?
+ return default_content_type
+ else
+ if page_part.page.layout.respond_to?(:content_type)
+ return page_part.page.layout.content_type
+ else
+ return default_content_type
+ end
+ end
+ end
+
def init_script(tag_id, text_area_id, content_type, filter)
@javascripts << ["/ace/src/ace.js", "/ace/src/ace-utils.js", "/ace/src/theme-twilight.js", "/ace/src/theme-textmate.js", "/ace/src/mode-html.js", "/ace/src/mode-css.js", "/ace/src/mode-coffee.js", "/ace/src/mode-javascript.js"]
@stylesheets << ["/ace/src/ace-resize.css"]
View
2  app/views/admin/page_parts/_page_part.html.haml
@@ -1,7 +1,7 @@
-ActionView::Base.send :include, Admin::AceHelper
-filter = page_part.filter
--layout = page_part.page.nil? ? "text/html" : page_part.page.layout.content_type
+-layout = content_type_for_page(page_part)
=init_script("editor_part_#{page_part.name.to_slug}_content", "part_#{page_part.name.to_slug}_content", layout, filter)
Something went wrong with that request. Please try again.