Sha256: c0866b59473a1d16b69080f5cfce8a954affbfdcae37ebf46e0308db96fa2a4c

Contents?: true

Size: 899 Bytes

Versions: 16

Compression:

Stored size: 899 Bytes

Contents

module Locomotive
  module Steam
    module Middlewares

      class WysihtmlCss

        GOOGLE_AMP_PATH = '_amp'

        def initialize(app, opts = {})
          @app = app
        end

        def call(env)
          status, headers, response = @app.call(env)

          if content?(env['steam.page'], env['steam.path'], response)
            url   = ::ActionController::Base.helpers.stylesheet_path('locomotive/wysihtml5_editor')
            html  = %(<link rel="stylesheet" type="text/css" href="#{url}">)
            response.first.gsub!('</head>', %(#{html}</head>))
          end

          [status, headers, response]
        end

        protected

        def content?(page, path, response)
          !path.starts_with?(GOOGLE_AMP_PATH + '/') &&
          !page.redirect &&
          page.response_type == 'text/html' &&
          response.first
        end

      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.2.0.alpha1 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.1.1 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.1.0 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.1.0.rc1 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.3 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.2 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.1 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.0 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.0.rc0 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.0.alpha3 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-3.4.1 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.0.alpha2 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-4.0.0.alpha1 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-3.4.0 lib/locomotive/steam/middlewares/wysihtml_css.rb
locomotivecms-3.3.0 lib/locomotive/steam/middlewares/wysihtml_css.rb