Sha256: b9c8a6be938170855d2e9ed924f2eee762f4f8247b06528ca7c7b75889a41deb

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

require 'digest/sha1'

class TagsDataset < Dataset::Base
  datasets = [:pages]
  datasets << :tag_sites if defined? Site
  uses *datasets
  
  def load
    create_tag "colourless"
    create_tag "green"
    create_tag "ideas"
    create_tag "sleep"
    create_tag "furiously"
    
    apply_tag :colourless, pages(:first)
    apply_tag :ideas, pages(:first), pages(:another), pages(:grandchild)
    apply_tag :sleep, pages(:first)
    apply_tag :furiously, pages(:first)
    
    create_page "library", :slug => "library", :class_name => 'LibraryPage', :body => 'Shhhhh.'
  end
  
  helpers do
    def create_tag(title, attributes={})
      attributes = tag_attributes(attributes.update(:title => title))
      tag = create_model Tag, title.symbolize, attributes
    end
    
    def tag_attributes(attributes={})
      title = attributes[:name] || "Tag"
      attributes = { 
        :title => title
      }.merge(attributes)
      attributes[:site] = sites(:test) if defined? Site
      attributes
    end
        
    def apply_tag(tag, *items)
      tag = tag.is_a?(Tag) ? tag : tags(tag)
      items.each { |i| i.attached_tags << tag }
    end
    
  end
 
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
radiant-taggable-extension-2.0.5 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.4 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.3 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.2 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.1 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.0 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.0.rc2 spec/datasets/tags_dataset.rb
radiant-taggable-extension-2.0.0.rc1 spec/datasets/tags_dataset.rb