Sha256: 5004a7fe97c7708b47071e3c7b4aa39a9df00231e2cf6547ba0b000eead181e6

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module Dashing
  class WidgetsController < ApplicationController

    before_filter :check_accessibility, only: :update
    before_filter :check_widget_name,   only: [:show, :update]
    before_filter :prepend_view_paths,  only: :show

    rescue_from ActionView::MissingTemplate, with: :template_not_found

    def show
      render file: withdet_path
    end

    def update
      data = params[:widget] || {}
      hash = data.merge(id: params[:name], updatedAt: Time.now.utc.to_i)
      Dashing.redis.publish("#{Dashing.config.redis_namespace}.create", hash.to_json)

      render nothing: true
    end

    private

    def check_widget_name
      raise 'bad widget name' unless params[:name] =~ /\A[a-zA-z0-9_\-]+\z/
    end

    def withdet_path
      "#{params[:name]}/#{params[:name]}"
    end

    def prepend_view_paths
      prepend_view_path engine_view_path
      prepend_view_path main_app_view_path
    end

    def engine_view_path
      Dashing::Engine.root.join('app', 'views', 'dashing', 'default_widgets')
    end

    def main_app_view_path
      Rails.root.join(Dashing.config.widgets_path)
    end

    def template_not_found
      raise "Count not find template for widget #{params[:name]}. Define your widget in #{main_app_view_path}"
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dashing-rails-1.0.3 app/controllers/dashing/widgets_controller.rb
dashing-rails-1.0.2 app/controllers/dashing/widgets_controller.rb
dashing-rails-1.0.1 app/controllers/dashing/widgets_controller.rb
dashing-rails-1.0.0 app/controllers/dashing/widgets_controller.rb