ruby – 用虾控制内容流

假设我们想在第一页上显示占用页面上半部分的标题.页面的下半部分应该填写我们的文章文本,文本应该继续流入后续页面,直到用完为止:

这是一个非常基本的布局场景,但我不明白如何在Prawn中实现它.

以下是从他们的在线文档导出的一些示例代码

pdf = Prawn::Document.new do
  text "The Prince",:align => :center,:size => 48
  text "Niccolò Machiavelli",:size => 20
  move_down 42

  column_Box([0,cursor],:columns => 3,:width => bounds.width) do
  text((<<-END.gsub(/\s+/,' ') + "\n\n") * 20)
   All the States and Governments by which men are or ever have been ruled,have been and are either Republics or Princedoms. Princedoms are either
   hereditary,in which the bla bla bla bla .....
   END
  end
end.render

但这将继续显示每个页面标题空间:

这样做的正确方法是什么?

解决方法

我一直在争取同样的问题.我结束了ColumnBox子类化,并添加一个帮助器来调用它:
module Prawn
  class Document

    def reflow_column_Box(*args,&block)
      init_column_Box(block) do |parent_Box|
        map_to_absolute!(args[0])
        @bounding_Box = ReflowColumnBox.new(self,parent_Box,*args)
      end
    end

    private

    class ReflowColumnBox < ColumnBox 
      def move_past_bottom 
        @current_column = (@current_column + 1) % @columns
        @document.y = @y
        if 0 == @current_column
          @y = @parent.absolute_top
          @document.start_new_page
        end
      end
    end
  end
end

那么它就像一个普通的列框一样被调用,但在下一个分页符将返回到父对象框.换行:

column_Box([0,:width => bounds.width) do

reflow_column_Box([0,:width => bounds.width) do

希望它可以帮助你.虾是相当低的水平,这是一把双刃剑,它有时不能做你需要的,但工具是在那里扩展和构建更复杂的结构.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...