Class: Awestruct::Extensions::Tagger
- Inherits:
-
Object
- Object
- Awestruct::Extensions::Tagger
- Defined in:
- lib/awestruct/extensions/tagger.rb
Defined Under Namespace
Modules: TagLinker Classes: TagStat
Instance Method Summary (collapse)
- - (Object) execute(site)
-
- (Tagger) initialize(tagged_items_property, input_path, output_path = 'tags', opts = {})
constructor
A new instance of Tagger.
- - (Object) sanitize(string)
Constructor Details
- (Tagger) initialize(tagged_items_property, input_path, output_path = 'tags', opts = {})
A new instance of Tagger
29 30 31 32 33 34 35 |
# File 'lib/awestruct/extensions/tagger.rb', line 29 def initialize(tagged_items_property, input_path, output_path='tags', opts={}) @tagged_items_property = tagged_items_property @input_path = input_path @output_path = output_path @sanitize = opts[:sanitize] || false @pagination_opts = opts end |
Instance Method Details
- (Object) execute(site)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/awestruct/extensions/tagger.rb', line 37 def execute(site) ||= {} all = site.send( @tagged_items_property ) return if ( all.nil? || all.empty? ) all.each do |page| = page. if ( && ! .empty? ) .each do |tag| tag = tag.to_s [tag] ||= TagStat.new( tag, [] ) [tag].pages << page end end end all.each do |page| page. = (page.||[]).collect{|t| [t]} page.extend( TagLinker ) end = .values .sort!{|l,r| -(l.pages.size <=> r.pages.size)} #ordered_tags = ordered_tags[0,100] .sort!{|l,r| l.to_s <=> r.to_s} min = 9999 max = 0 .each do |tag| min = tag.pages.size if ( tag.pages.size < min ) max = tag.pages.size if ( tag.pages.size > max ) end span = max - min if span > 0 slice = span / 6.0 .each do |tag| adjusted_size = tag.pages.size - min scaled_size = adjusted_size / slice tag.group = (( tag.pages.size - min ) / slice).ceil end else .each do |tag| tag.group = 0 end end .values.each do |tag| ## Optionally sanitize tag URL output_prefix = File.join( @output_path, sanitize(tag.to_s) ) = { :remove_input=>false, :output_prefix=>output_prefix, :collection=>tag.pages }.merge( @pagination_opts ) paginator = Awestruct::Extensions::Paginator.new( @tagged_items_property, @input_path, ) primary_page = paginator.execute( site ) tag.primary_page = primary_page end site.send( "#{@tagged_items_property}_tags=", ) end |
- (Object) sanitize(string)
99 100 101 102 103 104 105 106 |
# File 'lib/awestruct/extensions/tagger.rb', line 99 def sanitize(string) #replace accents with unaccented version, go lowercase and replace and space with dash if @sanitize string.to_s.urlize({:convert_spaces=>true}) else string end end |