Sha256: 8f86031019687abadd259919184f20a68a8b5dae675e3ea67eb2b49c34b8e021

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module Spontaneous::Rack::Back
  class Alias < Base
    get '/:schema_id/:id/:box_id' do
      klass = content_model.schema.to_class(params[:schema_id])
      if klass.alias?
        content_for_request do |content, box|
          options = {}
          if (query = params[:query])
            options[:search] = Regexp.new(query, Regexp::IGNORECASE)
          end
          targets = klass.targets(content, box, options).map { |t|
            { :id => t.id,
              :title => t.alias_title,
              :icon => t.exported_alias_icon }
          }
          json({
            :pages => 1,
            :total => targets.length,
            :page => 1,
            :targets => targets
          })
        end
      end
    end

    post '/:id/:box_id' do
      content_for_request(true) do |content, box|
        type = content_model.schema.to_class(params[:alias_id])
        position = (params[:position] || 0).to_i
        if box.writable?(user, type)
          instance = type.for_target(params[:target_id])
          if instance
            box.insert(position, instance)
            content.save
            json({
              :position => position,
              :entry => instance.entry.export(user)
            })
          end
        else
          forbidden!
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta5 lib/spontaneous/rack/back/alias.rb
spontaneous-0.2.0.beta4 lib/spontaneous/rack/back/alias.rb
spontaneous-0.2.0.beta3 lib/spontaneous/rack/back/alias.rb
spontaneous-0.2.0.beta2 lib/spontaneous/rack/back/alias.rb