ActiveAdmin
2018-06-12 15:00:38 1 举报
AI智能生成
ActiveAdmin概览模型
作者其他创作
大纲/内容
Rails
Template system
ActionView
FormBuilder
FormHelpers
RouteSet
ActiveAdmin.routes(self)config/routes.rb
路由入口调度
ActiveAdmin::Router.apply
Controller
BaseController
ResourceController
动态生成子Controller
Admin::BlogsController
index action
Admin::UsersController
determine_active_admin_layout
default layout: false
active_admin/app/views/layouts/active_admin.html.arb
helper_method :renderer_for
active_admin_namespace.view_factory[\"#{action}_page\"]
PageController
include ActiveAdmin::ViewHelpers
InheritedResources
Base
include Actions
index
show
Scaffolding style controllers
ActiveAdmin
View
Arbre
write view layer in ruby OO way,从AA中抽出来的
.arb template
ElementDOMTree基本单元抽象
Arbre::Rails::Rendering#render
helpers.render
.new
arbre_context
children
子标签 array like
.to_s
最终产生的渲染HTML内容
一般内容的构建通过content=来设置,用content方法来读取
content默认实现
children.to_s
include BuilderMethods
important! class_method: builder_method :div
成为Element实例方法Arbre::Element::BuilderMethods.instance_methods.sort
从而能达到在任何tag后的block内可以调到其它的tag方法只要是HTML valid的
使用/调用div
insert_tag
build_tag
tag is sub Element instance
特别注意: 调用时*args会被一路透传到调用tag.build(*args)处
特别注意:声明语句后的block语句是在对应的Tag/Component实例的上下文中执行的block也会被透传,从声明处一直到关联的Tag实例上下文中执行
所以可用方法因具体tag而不同!
暴露了dsl的弊病?要反复查代码,增加学习成本!
current_arbre_element
.build
约定的绘制方法,构建tag属性,内容等为最终.to_s方法负责
一般会被子tag重写,参TextNode
append_return_block(block.call(self)) if block
Tag
table
html5 support
content创建方式
调用时作为参数传入
div \"test div\"
通过block方式以内部add_child方式创建更灵活
div do span 'a span'end
invoke super
TextNode
just text element
Special Tag
P
para as builder_method
Document
no builder_method
Div
Context使用主入口
arbre/rails/template_handler.rb
current arbre element buffer as array
top is context itself
Component
just div tag with css class
ActiveAdminViews
with builder_method
TableFor
column
columns
without builder_method
Pages::Base
Index
config is pre-config page_presenter
.render_index
so config.block pass to insert_tag
结论:index后的block是在renderer_class实例中执行的,如IndexAsTable
进一步触发 insret_tag IndexTableFor
index_column
id_column
renderer_class refer to Views::IndexAsTable by :as key
Form
入口app/views/
active_admin
page
resource/*.arb
index.html.arb
insert_tag renderer_for(:index)
devise/**/*.erb
layouts
kaminari
!!! Rails是如何找到这个渲染路径的?
irb(main):018:0> puts Admin::TagsController.view_paths.map(&:to_s)/Users/cao/dev/cao9/app/views/rbox/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activeadmin-1.3.0/app/views/rbox/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-core-1.1.1/app/views/rbox/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/devise-4.4.3/app/views=> nilirb(main):019:0> Admin::TagsController._prefixes=> [\"admin/tags\
按照rails约定进行fallback动态查找!
覆盖方法
app/views
prepend_view_path
Formtastic
Input
great senmantic inputs
semantic_form_for
ActvieAdmin::Addons
顶层扩展app/inputs
TagsInput
DateTimePickerInput
Ransack
filters
Devise
authentication
Core ConfigDeveloper entry
Application
顶级配置,打造Admin应用
view_factory as hash
.register Blog do; xxx
DSL
具体资源定制
run_registration_block(&block)
instance_exec &block if block_given?
so block xxx exec in dsl instance
结论:register的block是在dsl实例中执行的
目的:专门用来配置Resource的!
Namespace
parse_registration_block
config.dsl = ResourceDSL.new(config) config.dsl.run_registration_block(&block)
conf is the resource
Resource
ResourceDSL(as dsl attr)
问题: index block的执行环境?
as active_admin_conf in controller
resource_class
User
Blog
Page
PageDSL
适合单页面逻辑,无具体model展示
ActiveAdmin.register page 'aPage' do; xxx
PagePresenter
new
block
options as hash
配置view各种属性的简单对象,在ActiveAdmin::Views::Pages各个类中使用
0 条评论
下一页
为你推荐
查看更多
抱歉,暂无相关内容