Sha256: 61f7762f7ea102e04ec20d78bfcb3104d7e5dc07180bef372fa557463de056af

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

module WLang
  class Scope
    class SinatraScope < ObjectScope

      def fetch(key, dialect = nil, unfound = nil)
        find_partial(key, subject) || super
      end

      def inspect
        "SinatraScope"
      end
      alias :to_s :inspect

    private

      def find_partial(key, app)
        find_internal_partial(key, app) || find_external_partial(key, app)
      end

      def find_internal_partial(key, app)
        return unless app.settings.templates[key]
        app.send(:compile_template, :wlang, key, {}, app.settings.views)
      end

      def find_external_partial(key, app)
        views = app.settings.views
        find_files(views, key) do |file|
          if engine = Tilt[file]
            tpl = app.template_cache.fetch(file) do
              options = if app.settings.respond_to?(:wlang)
                          app.settings.wlang
                        else
                          {}
                        end
              engine.new(file.to_s, 1, options)
            end
            return tpl
          end
        end
        nil
      end

      def find_files(folder, name, &bl)
        Path(folder).glob("#{name}.*").each(&bl)
      end

    end # class SinatraScope
  end # class Scope
end # module WLang

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wlang-3.0.1 lib/wlang/scope/sinatra_scope.rb
wlang-2.3.1 lib/wlang/scope/sinatra_scope.rb
wlang-2.3.0 lib/wlang/scope/sinatra_scope.rb
wlang-2.2.4 lib/wlang/scope/sinatra_scope.rb