Clone
Gustaf Neumann <neumann@wu-wien.ac.at>
committed
on 23 Apr 13
Object-method Reform: - changed interface to object specific commands by requiring an ensemble named "object". The rational behind is esseā€¦ Show more
Object-method Reform: - changed interface to object specific commands by requiring an   ensemble named "object". The rational behind is essentially   to use always the same info command to retrieve object   specific methods, no matter whether these are defined   on a plain object or an a class object (does not break   the "contract" what e.g. "info method" returns).

Now we define methods via:

  /cls/ method foo {args} {...body...}

  /cls/ object method foo {args} {...body...}

  /obj/ object method foo {args} {...body...}

Similarly, aliases, forwards and mixins are defined, e.g.

  /cls/ mixin add ...

  /cls/ object mixin add ...

  /obj/ object mixin add ...

  /obj/ require object method ...

The same change propagated as well to the "info" method.

Now we have:

  /cls/ info methods ...

  /cls/ info object methods ...

  /obj/ info object methods ...

Similar, the object parametererization uses

  /cls/ create obj -object-mixin M

  /cls/ create obj -object-filter f

  /metacls/ create cls -mixin M1 -object-mixin M2

  /metacls/ create cls -filter f1 -object-filter f2

- as a consequence,

 a) "/cls/ class method ...",

    "/cls/ class alias ...",

    "/cls/ class forward ...",

    "/cls/ class filter ...",

    "/cls/ class mixin ...",

    "/cls/ class info ..."

    "/obj/ class method require method ..."

    "/obj/ class method require public method ..."

    "/obj/ class method require protected method ..."

    "/obj/ class method require private method ..."

   were dropped

 b) "/obj/ method ....",

    "/obj/ alias ....",

    "/obj/ forward ...."

    "/obj/ filter ...."

    "/obj/ mixin ...."

    "/obj/ info method*"

    "/cls/ create obj -mixin M"

    "/cls/ create obj -filter f"

    "/obj/ method require method ..."

    "/obj/ method require public method ..."

    "/obj/ method require protected method ..."

    "/obj/ method require private method ..."

    were dropped

- added package nx::class to allow optionally the "class" notation

 "/cls/ class method ..." (and friends, see (a)), and

 "/cls/ class info ...

- added package nx::plain-object-method to allow optionally plain method

 b) "/obj/ method ...." (and friends, see (b))

- add support to slots to use ensemble methods as setters

Show less

2-1-0-rc + 55 more
apps/utils/nxdoc (+18 -16)
8 8   Class create CLI {
9 9    
10 10     #
11 11     # rendering
12 12     #
13 13     :property {outdir "."}
14 14     :property {format "html"}
15 15     :property {theme "yuidoc"}
16 16     :property {layout "many-to-many"}
17 17    
18 18     #
19 19     # doc project
20 20     #
21 21     :property doctitle
22 22     :property {docversion 0.1}
23 23     :property docurl
24 24     :property docbaseurl
25 25     :property {validation:switch false}
26 26    
27 27     #
28       # input
  28     # frontend
29 29     #
  30     :property {frontend dc}
30 31     :property includes
31       :property {excludes ""}
  32     :property excludes
32 33     :property indexfiles:alias
33 34
34 35     :protected property sources:1..* {
  36       set :incremental 1
35 37       set :config false
36 38     }
37 39
38 40     #
39 41     # auxiliary
40 42     #
41 43
42 44     :private method barf {msg} {
43 45       return -code error "NXDoc: $msg"
44 46     }
45 47
46 48     :protected method ... args {
47         :sources [concat {*}[split $args :]]
  49       foreach i $args {
  50         set idx [string first : $i]
  51         if {$idx == -1} continue;
  52         dict lappend :sources [string range $i 0 [expr {$idx - 1}]] [string range $i [expr {$idx + 1}] end]
48 53       }
  54     }
49 55
50 56     :protected method indexfiles {paths} {
51 57       #
52 58       # TODO: Should we provide for an auto-lookup of nxdocIndex files,
53 59       # similar to tclIndex or pkgIndex.tcl?
54 60       #
55 61
56 62       #
57 63       # Some sanity checks first ...
58 64       #
59 65       set sources [list]
60 66       foreach p $paths {
61 67         set p [file normalize $p]
62 68         if {[file exists $p] && [file readable $p]} {
63 69           lappend sources [list source $p]
64 70         } else {
65 71           :barf "Cannot find or read the index file '$p'"
66 72         }
67 73       }
68 74      
 
87 93         :barf "Sourcing index files failed with error message '$err'"
88 94       }
89 95      
90 96       lappend :includes {*}[$i eval [list ::nxdoc::internal::getIndexedCmds 1]]
91 97       interp delete $i
92 98     }
93 99
94 100     :protected class method objectparameter {} {
95 101       set slots [:info slot objects]
96 102       foreach slot $slots {
97 103         lappend defs([$slot position]) [$slot getParameterSpec]
98 104       }
99 105       set parameterdefinitions [list]
100 106       foreach p [lsort [array names defs]] {
101 107         lappend parameterdefinitions {*}$defs($p)
102 108       }
103 109       return [concat $parameterdefinitions ...:alias,args]
104 110     }
105 111    
106 112     :protected method init {} {
107         set prj [@project new \
  113
  114       set prj [@project newFromSources \
  115                    -frontend ${:frontend} \
  116                    {*}[expr {[info exists :includes]?[list -include ${:includes}]:""}] \
  117                    {*}[expr {[info exists :excludes]?[list -exclude ${:excludes}]:""}] \
  118                    ${:sources} \
108 119                    -name ${:doctitle} \
109 120                    -url ${:docurl} \
110 121                    -version ${:docversion} \
111                      -sources ${:sources}]
  122                    {*}[expr {${:validation}?"-mixin ::nx::doc::@project::Validator":""}]]
112 123      
113         processor process \
114             -sandboxed \
115             {*}[expr {${:validation}?"-validate":""}] \
116             {*}[expr {[info exists :includes]?"-include [list ${:includes}]":""}] \
117             $prj
118 124
119         make doc \
120             -format ${:format} \
121             $prj \
122             -theme ${:theme} \
123             -layout ${:layout} \
124             -outdir ${:outdir}
  125      
  126       $prj write -format ${:format} -theme ${:theme} -layout ${:layout} -outdir ${:outdir}
125 127     }
126 128   }
127 129   namespace export CLI
128 130 }
129 131
130 132 namespace import -force ::nx::doc::CLI
131 133 #
132 134 # nxdoc -outdir /tmp/ -format html -theme yuidoc package:nsf
133 135 #
134 136 CLI new {*}$argv
135 137