ActiveAdmin
2018-06-12 15:00:38   1  举报             
     
         
 AI智能生成
  ActiveAdmin概览模型
    作者其他创作
 大纲/内容
  Rails    
     Template system  
     ActionView    
     FormBuilder  
     FormHelpers  
     RouteSet    
     ActiveAdmin.routes(self)
config/routes.rb
    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  
     View    
     Arbre    
     write view layer in ruby OO way,从AA中抽出来的  
     .arb template    
     Element
DOMTree基本单元抽象
    DOMTree基本单元抽象
 Arbre::Rails::Rendering#render    
     helpers.render  
     .new    
     arbre_context    
     delegate assigns, helpers  
     children    
     子标签 array like  
     .to_s    
     最终产生的渲染HTML内容  
     一般内容的构建通过content=来设置,用content方法来读取    
     content默认实现    
     children.to_s  
     include BuilderMethods    
     important! class_method: builder_method :div    
     Tag类加载时定义了标签方法, 如 div, para  
     成为Element实例方法
Arbre::Element::BuilderMethods.instance_methods.sort
    
    Arbre::Element::BuilderMethods.instance_methods.sort
 从而能达到在任何tag后的block内可以调到其它的tag方法
只要是HTML valid的
    只要是HTML valid的
 使用/调用div    
     insert_tag    
     build_tag    
     tag is sub Element instance  
     invoke tag.build(*args, &block)  
     特别注意: 调用时*args会被一路透传到调用tag.build(*args)处  
     特别注意:声明语句后的block语句是在对应的Tag/Component实例的上下文中执行的
block也会被透传,从声明处一直到关联的Tag实例上下文中执行
    block也会被透传,从声明处一直到关联的Tag实例上下文中执行
 所以可用方法因具体tag而不同!  
     暴露了dsl的弊病?
要反复查代码,增加学习成本!
    要反复查代码,增加学习成本!
 current_arbre_element    
     children  
     .build    
     约定的绘制方法,构建tag属性,内容等
为最终.to_s方法负责
    为最终.to_s方法负责
 一般会被子tag重写,参TextNode  
     append_return_block(block.call(self)) if block  
     Tag    
     para,  div, span, html, input, li, form, footer, hr  
     table  
     html5 support  
     content创建方式    
     调用时作为参数传入    
     div "test div"  
     通过block方式以内部add_child方式创建
更灵活
    更灵活
 div do
span 'a span'
end
    span 'a span'
end
 .build    
     invoke super  
     TextNode    
     just text element  
     Special Tag    
     P    
     para as builder_method  
     Document    
     no builder_method  
     Div  
     Context
使用主入口
    使用主入口
 Arbre::Context.new(assigns, self) {
#{template.source}
}.to_s
    #{template.source}
}.to_s
 arbre/rails/template_handler.rb  
     here self is helpers from caller, eg. rails  
     The contents of the block are instance eval'd within the Context 
object. This means that you lose context to the outside world from
within the block. To pass local variables into the Context, use the
assigns param.
    object. This means that you lose context to the outside world from
within the block. To pass local variables into the Context, use the
assigns param.
 current_arbre_element    
     within, with_current_arbre_element(tag)  
     current arbre element buffer as array    
     top is context itself  
     Component    
     just div tag with css class  
     ActiveAdmin
Views
    Views
 Component    
     with builder_method    
     Panel, TableFor, BlankSlate  
     TableFor    
     column  
     columns  
     without builder_method    
     Header, Footer, TitleBar, IndexAsTable, TabbedNavigation, ActionItems  
     Pages::Base    
     Index    
     config is pre-config page_presenter  
     .render_index    
     insert_tag(renderer_class, config, collection)    
     so config.block pass to insert_tag  
     结论:index后的block是在renderer_class实例中执行的,如IndexAsTable    
     table_for collection, table_options do |t|
table_config_block = page_presenter.block || default_table
instance_exec(t, &table_config_block)
end
    table_config_block = page_presenter.block || default_table
instance_exec(t, &table_config_block)
end
 进一步触发 insret_tag IndexTableFor    
     index_column  
     id_column  
     renderer_class refer to Views::IndexAsTable by :as key  
     Form    
     for new, edit page  
     Layout, Page, Show  
     delegate :active_admin_config, :controller, :params, to: :helpers  
     入口
app/views/
    app/views/
 active_admin    
     page  
     resource/*.arb    
     index.html.arb    
     insert_tag renderer_for(:index)
  
     devise/**/*.erb  
     layouts    
     arb, erb  
     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
=> nil
irb(main):019:0> Admin::TagsController._prefixes
=> ["admin/tags", "active_admin/resource", "active_admin/base", "inherited_resources/base", "application"]
    /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
=> nil
irb(main):019:0> Admin::TagsController._prefixes
=> ["admin/tags", "active_admin/resource", "active_admin/base", "inherited_resources/base", "application"]
 按照rails约定进行fallback动态查找!    
     覆盖方法    
     app/views  
     prepend_view_path  
     Formtastic    
     Input    
     great senmantic inputs  
     semantic_form_for  
     ActvieAdmin::Addons    
     顶层扩展
app/inputs
    app/inputs
 TagsInput  
     DateTimePickerInput  
     Ransack    
     filters  
     Devise    
     authentication  
     Core Config
Developer entry
    Developer entry
 ActiveAdmin  
     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    
     .register Blog do; xxx    
     parse_registration_block    
     config.dsl = ResourceDSL.new(config)
config.dsl.run_registration_block(&block)
    config.dsl.run_registration_block(&block)
 conf is the resource  
     Resource    
     ResourceDSL(as dsl attr)    
     block statement: index(options = {}, &block)    
     问题: index block的执行环境?  
     config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block)  
     show page: show(options = {}, &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 条评论
 下一页
 为你推荐
 查看更多
    
  
   
   
   
   
 