Method: Deplate::Core#set_top_heading

Defined in:
lib/deplate/core.rb

#set_top_heading(heading, text) ⇒ Object

Set the current top heading.

heading

Heading object

text

The output filename base



2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
# File 'lib/deplate/core.rb', line 2317

def set_top_heading(heading, text)
    if heading.level <= @options.split_level
        fname = nil
        sfx   = @options.suffix
        # dir   = @options.dir
        if @output_headings.include?(heading)
            maj = top_heading_idx(heading)
        else
            heading.top_heading = heading
            push_top_heading(heading)
            maj = @output_headings.size - 1
            unless text or !@options.multi_file_output
                afn = @variables['autoFileNames']
                if afn
                    fname = Deplate::Core.clean_filename(heading.get_text)[0..20]
                    c = auto_numbered(fname)
                    if c
                        fname = Deplate::Core.canonic_file_name(fname, sfx, :maj => c, :min => 0, :raw => true)
                        auto_numbered(fname, :inc => 1)
                    else
                        fname = Deplate::Core.canonic_file_name(fname, sfx, :raw => true)
                        auto_numbered(fname, :set => 0)
                    end
                else
                    # if @variables['autoBaseName']
                    #     fname = File.basename(@current_source, '.*')
                    #     fmaj  = if auto_numbered(fname)
                    #                 auto_numbered(fname, :inc => 1)
                    #             else
                    #                 auto_numbered(fname, :set => 0)
                    #             end
                    # else
                    #     fname = File.basename(@dest, '.*')
                    #     fmaj  = maj
                    # end
                    fname = @variables['autoBaseName'] ? @current_source : @dest
                    fname = File.basename(fname, '.*')
                    fmaj  = if auto_numbered(fname)
                                auto_numbered(fname, :inc => 1)
                            # <+TBD+>
                            elsif @accum_elements.size == 1 and 
                                @accum_elements[0].kind_of?(Deplate::Element::PotentialPageBreak)
                                auto_numbered(fname, :set => 0)
                            else
                                auto_numbered(fname, :set => 1)
                            end
                    fname = Deplate::Core.canonic_file_name(fname, sfx, :maj => fmaj, :min => 0, :raw => true)
                end
            end
        end
        if !@options.multi_file_output
            # fname = ""
            fname = @dest
        else
            if text
                fname = Deplate::Core.canonic_file_name(text, sfx)
            end
            if fname
                fname = Deplate::Core.get_out_fullname(fname, nil, @options)
            end
            @output.simulate_reset
        end
        # if fname and @options.multi_file_output
        if fname
            heading.destination = @output_filename[maj] = fname
        end
        log(["Set top heading", maj, (text||"nil"), fname], :debug)
    end
end