lib/fdoc.fy in fancy-0.9.0 vs lib/fdoc.fy in fancy-0.10.0

- old
+ new

@@ -80,38 +80,49 @@ # Currently we just load any files given on ARGV. ARGV each: |file| { Fancy CodeLoader load_compiled_file(file) } @documented_objects = @documented_objects select_keys: |k| { @objects_to_remove includes?: k . not } + # display progress + t = Thread new: { + loop: { + "." print + sleep: 0.1 + } + } + # by now simply produce a apidoc/fancy.jsonp file. json = JSON new: @documented_objects add_github_links: add_github_links github_repo: github_repo json write: (File expand_path("fancy.jsonp", output_dir)) - ["Open your browser at " ++ output_dir ++ "index.html ", + ["\n\nOpen your browser at " ++ output_dir ++ "index.html ", " " ++ (json classes size) ++ " classes. ", " " ++ (json methods size) ++ " methods. ", " " ++ (json objects size) ++ " other objects. "] println + + t kill } class JSON { read_slots: ['classes, 'methods, 'blocks, 'objects] def initialize: documented add_github_links: @add_github_links github_repo: @github_repo { @documented_objects = documented - is_class = |o| { o kind_of?: Module } - is_method = |o| { o kind_of?: Rubinius CompiledMethod } - is_block = |o| { o kind_of?: Rubinius BlockEnvironment } - all_other = |o| { - [is_class, is_method, is_block] all?() |b| { b call: [o] == false } + class? = @{ kind_of?: Module } + method? = @{ kind_of?: Rubinius CompiledMethod } + block? = @{ kind_of?: Rubinius BlockEnvironment } + other? = |o| { + [class?, method?, block?] any?: @{ call: [o] } . not } - @classes = @documented_objects keys select: is_class - @methods = @documented_objects keys select: is_method - @blocks = @documented_objects keys select: is_block - @objects = @documented_objects keys select: all_other + types = [class?, method?, block?, other?] + + @classes, @methods, @blocks, @objects = types map: |type| { + @documented_objects keys select: type + } } def string_to_json: obj { obj to_s inspect } @@ -179,31 +190,36 @@ attr["#{type}s" intern()] [n to_s]: mattr } } def generate_map { - map = <['title => "Fancy Documentation", 'date => Time now() to_s(), - 'classes => <[]>, 'methods => <[]>, 'objects => <[]> ]> + map = <[ + 'title => "Fancy Documentation", + 'date => Time now to_s, + 'classes => <[]>, + 'methods => <[]>, + 'objects => <[]> + ]> - methods = @methods dup() + methods = @methods dup @classes each: |cls| { name = cls name gsub("::", " ") doc = Fancy Documentation for: cls attr = <[ 'doc => doc format: 'fdoc, 'instance_methods => <[]>, 'methods => <[]>, - 'ancestors => cls ancestors() map: |c| { (c name || "") gsub("::", " ") } + 'ancestors => cls ancestors map: @{ name to_s gsub("::", " ") } ]> popuplate_methods: cls on: attr type: 'instance_method known: methods popuplate_methods: cls on: attr type: 'method known: methods map['classes][name]: attr } methods each: |cm| { - cls = cm scope() module() + cls = cm scope module cls_name = cls name gsub("::", " ") cls_attr = map['classes][cls_name] full_name = "#{cls_name}##{cm name}" @@ -221,10 +237,10 @@ def write: filename call: name ("fancy.fdoc") { map = generate_map json = to_json: map js = "(function() { #{name}(#{@add_github_links}, #{@github_repo inspect}, #{json}); })();" - File open: filename modes: ['write] with: |out| { out print: js } + File open: filename modes: ['write] with: @{ print: js } } } class Formatter { """