Sha256: 31a98002408b1d14c6ab4cecedd7216a22df0d74a427b594230551e0a7b1e832

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

#   Copyright 2011 innoQ Deutschland GmbH
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

def IqRdf.rails_template(template)
  <<-EOV
  document = IqRdf::Document.new()
  #{template.source}
  if params[:format].to_s == "ttl"
    controller.response.headers["Content-Type"] ||= 'text/turtle'
    document.to_turtle
  elsif  params[:format].to_s == "nt"
    controller.response.headers["Content-Type"] ||= 'text/plain'
    document.to_ntriples
  elsif params[:format].to_s == "rdf"
    controller.response.headers["Content-Type"] ||= 'application/xml+rdf'
    document.to_xml
  else # Default => turtle
    controller.response.headers["Content-Type"] ||= 'text/turtle'
    document.to_turtle
  end
  EOV
end

module ActionView

  if Rails.version >= "3"

    class Template::Handlers::IqRdf
      def self.call(template)
        IqRdf.rails_template(template)
      end
    end
    ActionView::Template.register_template_handler('iqrdf', ActionView::Template::Handlers::IqRdf)

  else

    class TemplateHandlers::IqRdf < ActionView::TemplateHandler
      include ActionView::TemplateHandlers::Compilable
      def compile(template)
        IqRdf.rails_template(template)
      end
    end
    ActionView::Template.register_template_handler('iqrdf', ActionView::TemplateHandlers::IqRdf)

  end
 

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
iq_rdf-0.1.15 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.14 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.13 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.12 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.10 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.8 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.7 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.6 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.5 lib/iq_rdf/rails/iq_rdf.rb
iq_rdf-0.1.4 lib/iq_rdf/rails/iq_rdf.rb