Module: AppKit

Defined in:
lib/app_kit.rb,
lib/app_kit/dsl.rb,
lib/app_kit/field.rb,
lib/app_kit/action.rb,
lib/app_kit/engine.rb,
lib/app_kit/version.rb,
lib/app_kit/resource.rb,
app/helpers/app_kit/attribute_helper.rb,
app/helpers/app_kit/dashboard_helper.rb,
app/helpers/app_kit/application_helper.rb,
app/controllers/app_kit/dashboard_controller.rb,
app/controllers/app_kit/resources_controller.rb,
app/controllers/app_kit/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, AttributeHelper, DashboardHelper, Dsl, FilterHelper, HistoryHelper, NavigationHelper, PathHelper, ResourceHelper, TableHelper, Views Classes: Action, Application, ApplicationController, Configuration, DashboardController, Engine, Field, FilterFormBuilder, InstallGenerator, NavigationItem, Resource, ResourceGenerator, ResourcesController, User

Constant Summary collapse

LOAD_PATH =
[File.expand_path('app/app_kit', Rails.root)]
VERSION =
"0.0.2"
@@application =
Application.new

Class Method Summary collapse

Class Method Details

.applicationObject



40
41
42
# File 'lib/app_kit.rb', line 40

def self.application
  @@application
end

.register(model, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/app_kit/dsl.rb', line 2

def self.register(model, &block)
  # create resource controller
  return unless ActiveRecord::Base.connection.table_exists? model.table_name
  resource_name = model.name.demodulize.underscore.pluralize
  controller_name = model.name.demodulize.pluralize
  controller = AppKit.const_set("#{controller_name}Controller",
                                Class.new(ResourcesController))
  controller.resource = Resource.new(model)
  # process resource dsl
  controller.resource.instance_exec(&block)  if block_given?
  controller.resource.controller_name = controller.controller_name
  controller.prepend_view_path("app/views/#{model.name.underscore.pluralize}")

  # draw controller routes
  AppKit::Engine.routes.append do
    resources resource_name.to_sym do
      controller.resource.has_many_associations.each do |assoc|
        resources assoc.name.to_s.pluralize, only: [:new]
      end
      member do
        get 'history' => :history, :as => :history
        get 'version/:version_id' => :version, :as => :version
        controller.resource.member_actions.each do |name,action|
          get action.name, action: 'perform_action', action_name: 'deactivate'
        end
      end
      collection do
        get 'versions/:version_id' => :show_version, :as => :show_version
      end
    end
  end
end

.setup(&block) ⇒ Object



34
35
36
# File 'lib/app_kit/dsl.rb', line 34

def self.setup(&block)
    AppKit.application.setup!(&block)
end