加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 用虾控制内容流

发布时间:2020-12-16 19:26:09 所属栏目:百科 来源:网络整理
导读:假设我们想在第一页上显示占用页面上半部分的标题.页面的下半部分应该填写我们的文章文本,文本应该继续流入后续页面,直到用完为止: 这是一个非常基本的布局场景,但我不明白如何在Prawn中实现它. 以下是从他们的在线文档导出的一些示例代码: pdf = Prawn::D
假设我们想在第一页上显示占用页面上半部分的标题.页面的下半部分应该填写我们的文章文本,文本应该继续流入后续页面,直到用完为止:

这是一个非常基本的布局场景,但我不明白如何在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+/,' ') + "nn") * 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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读