Class: Generators::HtmlFile

Inherits:
ContextUser show all
Defined in:
lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb,
lib/generators/templates/application/merb_stack/doc/rdoc/generators/merb_generator.rb

Overview

Handles the mapping of a file’s information to HTML. In reality, a file corresponds to a TopLevel object, containing modules, classes, and top-level methods. In theory it could contain attributes and aliases, but we ignore these for now.

Constant Summary collapse

@@f_seq =
"F00000000"

Instance Attribute Summary collapse

Attributes inherited from ContextUser

#context

Instance Method Summary collapse

Methods inherited from ContextUser

#add_table_of_sections, #build_alias_summary_list, #build_class_list, #build_constants_summary_list, #build_include_list, #build_method_detail_list, #build_method_summary_list, #build_requires_list, #collect_methods, #diagram_reference, #document_self, #find_symbol, #href, #potentially_referenced_list

Methods included from MarkUp

#cvs_url, #markup, #style_url

Constructor Details

#initialize(context, options, file_dir) ⇒ HtmlFile

Returns a new instance of HtmlFile.



756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 756

def initialize(context, options, file_dir)
    super(context, options)
    @@f_seq  = @@f_seq.succ
    @f_seq   = @@f_seq
    @values = {}

    @path = http_url(file_dir)
    @source_file_path = File.expand_path(@context.file_relative_name).gsub("\/doc\/", "/")
    @name = @context.file_relative_name

    collect_methods
    AllReferences.add(name, self)
    context.viewer = self
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



754
755
756
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 754

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



753
754
755
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 753

def path
  @path
end

Instance Method Details

#<=>(other) ⇒ Object



899
900
901
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 899

def <=>(other)
    self.name <=> other.name
end

#arefObject



783
784
785
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 783

def aref
    @f_seq
end

#file_attribute_valuesObject



880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 880

def file_attribute_values
    full_path = @context.file_absolute_name
    short_name = File.basename(full_path)

    @values["title"] = CGI.escapeHTML("File: #{short_name}")

    if @context.diagram
        @values["diagram"] = diagram_reference(@context.diagram)
    end

    @values["short_name"]   = CGI.escapeHTML(short_name)
    @values["full_path"]    = CGI.escapeHTML(full_path)
    @values["dtm_modified"] = @context.file_stat.mtime.to_s

    if @options.webcvs
        @values["cvsurl"] = cvs_url( @options.webcvs, @values["full_path"] )
    end
end

#filename_to_labelObject



775
776
777
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 775

def filename_to_label
    @context.file_relative_name.gsub(/%|\/|\?|\#/) {|s| '%' + ("%x" % s[0]) }
end

#full_file_sourceObject



804
805
806
807
808
809
810
811
812
813
814
815
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 804

def full_file_source
    ret_str = ""
    File.open(@source_file_path, 'r') do |f| 
        while(!f.eof?) do
            ret_str += f.readline()
        end
    end
    ret_str
rescue
    "file not found -#{@source_file_path}-"
    #@source_file_path
end

#full_nameObject



792
793
794
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 792

def full_name
    @context.file_absolute_name
end

#http_url(file_dir) ⇒ Object



771
772
773
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 771

def http_url(file_dir)
    File.join(file_dir, @context.file_relative_name.tr('.', '_')) + ".html"
end

#parent_nameObject



800
801
802
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 800

def parent_name
    nil
end

#scopeObject



796
797
798
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 796

def scope
    @context.file_relative_name.gsub(/\/#{name}$/, '')
end

#seqObject



779
780
781
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 779

def seq
    @f_seq
end

#value_hashObject



817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 817

def value_hash
    file_attribute_values
    add_table_of_sections

    @values["charset"]   = @options.charset
    @values["href"]      = path
    @values["style_url"] = style_url(path, @options.css)
    @values["file_seq"] =  seq

    #pulling in the source for this file
    #@values["source_code"] = @context.token_stream

    @values["file_source_code"] = CGI.escapeHTML(full_file_source)

    if @context.comment
        d = markup(@context.comment)
        @values["description"] = d if d.size > 0
    end

    ml = build_method_summary_list
    @values["methods"] = ml unless ml.empty?

    il = build_include_list(@context)
    @values["includes"] = il unless il.empty?

    rl = build_requires_list(@context)
    @values["requires"] = rl unless rl.empty?


    file_context = @context

    @values["sections"] = @context.sections.map do |section|

        secdata = {
            "sectitle" => section.title,
            "secsequence" => section.sequence,
            "seccomment" => markup(section.comment)
        }

        cl = build_class_list(0, @context, section, file_context)
        @values["classlist"] = cl unless cl.empty?

        mdl = build_method_detail_list(section)
        secdata["method_list"] = mdl unless mdl.empty?

        al = build_alias_summary_list(section)
        secdata["aliases"] = al unless al.empty?

        co = build_constants_summary_list(section)
        @values["constants"] = co unless co.empty?

        secdata
    end

    @values
end

#write_on(f) ⇒ Object



874
875
876
877
878
# File 'lib/generators/templates/application/merb_core/doc/rdoc/generators/merb_generator.rb', line 874

def write_on(f)
    value_hash
    template = TemplatePage.new(RDoc::Page::SRC_BODY,RDoc::Page::FILE_PAGE, RDoc::Page::METHOD_LIST)
    template.write_html_on(f, @values)
end