Sha256: b3cb3ac29c7a689eb08b5a6ffbcf7f1412793e557583ebaa881734c935a2004d

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

# encoding: UTF-8

require 'sprockets'

module Spontaneous
  module Rack
    module Helpers
      def json(response)
        content_type 'application/json', :charset => 'utf-8'
        response.serialise_http(user)
      end

      def application_assets
        @application_assets_compiler ||= Spontaneous::Asset::AppCompiler.new(Spontaneous.gem_dir, Spontaneous.root)
      end

      def style_url(style)
        style = "#{style}.css" unless style =~ /\.css$/
        if (compiled_asset = application_assets.manifest.assets[style])
          return "#{NAMESPACE}/assets/#{compiled_asset}"
        end
        # TODO: use the sprockets environment to append a modification time to the non-compiled URL
        "#{NAMESPACE}/css/#{style}"
      end

      def script_url(script)
        script = "#{script}.js" unless script =~ /\.js$/

        if (compiled_asset = application_assets.manifest.assets[script])
          return "#{NAMESPACE}/assets/#{compiled_asset}"
        end
        # TODO: use the sprockets environment to append a modification time to the non-compiled URL
        "#{NAMESPACE}/js/#{script}"
      end

      def script_list(scripts)
        scripts.map do |script|
          script = "#{script}.js" unless script =~ /\.js$/
          src = script_url(script)
          size = 0
          if (asset = application_assets.manifest.files[File.basename(src)])
            size = asset["size"]
          else
            src = "#{NAMESPACE}/js/#{script}"
            path = Spontaneous.application_dir("/js/#{script}")
            size = File.size(path)
          end
          [src, size]
        end.to_json
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/rack/helpers.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/rack/helpers.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/rack/helpers.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/rack/helpers.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/rack/helpers.rb