0

以下 ruby​​ 代码自动在 VoodooPad 中创建页面,并为每个页面添加元标记。

vp = app("VoodooPad.app")
doc = vp.open vpdoc

page_names = [@name]

if self.class.to_s.match('Stake::Stack')
    # Create the release notes page. Only run on parent stack
    notes = "#{@name} Release Notes"
    page_names.push notes
    doc.remove :with_name => notes
    doc.create :new => :page, :with_name => notes, :with_content => self.release_notes
end

# Create the settings page
settings = "#{@name} Settings"
page_names.push settings
doc.remove :with_name => settings
doc.create :new => :page, :with_name => settings, :with_content => self.to_md

page_names.each do |page_name|
    # Add the meta tags to the product page
    page = doc.pages[page_name]
    puts page_name
    page.remove_meta_record :with_key => "description"
    page.remove_meta_record :with_key => "url"
    page.remove_meta_record :with_key => "name"
    page.remove_meta_record :with_key => "image"
    page.remove_meta_record :with_key => "version"
    page.remove_meta_record :with_key => "stacks_version"
    page.add_meta_record :with_value => {'version'          => @version_str}
    page.add_meta_record :with_value => {'stacks_version'   => @stacks_version}
    page.add_meta_record :with_value => {'subtitle'         => @subtitle}
    page.add_meta_record :with_value => {'url'              => @info_url}
    page.add_meta_record :with_value => {'image'            => @basename + '@128.png'}
    page.add_meta_record :with_value => {'name'             => @name}
end

在每个块中,相同的元标记被添加到 3 个页面。但是,标签仅添加到 3 个页面中的 2 个。如果我们以“徽章”的名称为例,这里是我的页面名称。

Badges
Badges Release Notes
Badges Settings

无论数组的顺序如何,“徽章”页面总是得到正确标记。但是,对于其他 2 页,首先处理的是。另一个没有。

我想可能是页面名称中的空格。不过,这没关系。我得到同样的行为。如果您注意到代码也会正确地动态创建这两个页面。

我也尝试过添加睡眠,认为这可能是一个时间问题。没有。

我被困住了。帮助。

4

1 回答 1

0

我想到了。我添加标签的页面不能是当前活动页面。

vp = app("VoodooPad.app")
doc = vp.open vpdoc

page_names = Array.new

if self.class.to_s.match('Stake::Stack')
    # Only the parent stack has a main page
    page_names.push @name

    # Create the release notes page. Only run on parent stack
    notes = "#{@name} Release Notes"
    page_names.push notes
    doc.remove :with_name => notes
    doc.create :new => :page, :with_name => notes, :with_content => self.release_notes
end

# Create the settings page
settings = "#{@name} Settings"
page_names.push settings
doc.remove :with_name => settings
doc.create :new => :page, :with_name => settings, :with_content => self.to_md

# Have to open to different page to ensure its not open when I add meta tags.
doc.open_page :with_name => 'index'

page_names.each do |page_name|
    # Add the meta tags to the product page
    page = doc.pages[page_name]
    puts page_name
    page.remove_meta_record :with_key => "description"
    page.remove_meta_record :with_key => "url"
    page.remove_meta_record :with_key => "name"
    page.remove_meta_record :with_key => "image"
    page.remove_meta_record :with_key => "version"
    page.remove_meta_record :with_key => "stacks_version"
    page.add_meta_record :with_value => {'version'          => @version_str}
    page.add_meta_record :with_value => {'stacks_version'   => @stacks_version}
    page.add_meta_record :with_value => {'subtitle'         => @subtitle}
    page.add_meta_record :with_value => {'url'              => @info_url}
    page.add_meta_record :with_value => {'image'            => "#{@basename}@128.png".downcase}
    page.add_meta_record :with_value => {'name'             => @name}
    # Open current page to ensure next page is not open or else cannot add tags
    doc.open_page :with_name => page_name
end
于 2012-12-11T03:44:17.873 回答