Class: SitemapsTasks

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/sitemaps_tasks.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SitemapsTasks

Returns a new instance of SitemapsTasks.



10
11
12
13
14
# File 'lib/sitemaps_tasks.rb', line 10

def initialize args = {}
  @host = args[:domain]
  @lang = args[:lang]
  @verbose = args[:verbose]
end

Instance Method Details

#generateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
98
99
100
101
102
103
104
105
106
# File 'lib/sitemaps_tasks.rb', line 16

def generate
  travel_site = Site.where( :domain => @host, :lang => @lang ).first
  travel_tag = Tag.mobi

  @reports = Report.or( :site => travel_site )

  # @galleries = Gallery.any_of( :site => travel_site, :tag => travel_tag )
  @galleries = []

  # @videos = Video.any_of( :site => travel_site, :tag => travel_tag )
  @videos = []

  # @tags = Tag.where( :site => travel_site )
  @tags = []

  @cities = City.all

  @venues = Venue.all

  # @users = User.all
  @users = []

  # @meta = [ { :url => cities_path } ]
  @meta = []

  #
  # the (builder) view
  #
  xml = Builder::XmlMarkup.new(:indent=>2)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do

    @reports.each do |report|
      puts "Report: #{report.name}" if @verbose
      xml.url do
        xml.loc "http://#{@host}/#{@lang}/reports/view/#{report.name_seo}"
        xml.lastmod self.pretty_date report.created_at
      end
    end
    
    @galleries.each do |g|
      xml.url do
        xml.loc "http://#{@host}/#{@lang}/galleries/show/#{g.galleryname}"
        xml.lastmod pretty_date g.created_at
      end
    end
    
    @cities.each do |c|
      puts "City: #{c.name}" if @verbose
      xml.url do
        xml.loc "http://#{@host}/#{@lang}/cities/travel-to/#{c.cityname}"
        xml.lastmod pretty_date c.created_at
      end
    end
    
    @tags.each do |c|
      xml.url do
        xml.loc "http://#{@host}/#{@lang}/tags/show/#{c.name_seo}"
        xml.lastmod pretty_date c.created_at
      end
    end
    
    @users.each do |user|
      xml.url do
        xml.loc "http://#{@host}/#{@lang}/users/show/#{user.username}"
        xml.lastmod pretty_date user.created_at
      end
    end
    
    @venues.each do |c|
      puts "Venue: #{c.name}" if @verbose
      xml.url do
        xml.loc "http://#{@host}/#{@lang}/venues/show/#{c.name_seo}"
        xml.lastmod pretty_date c.created_at
      end
    end

    # @meta.each do |m|
    #   xml.url do
    #     xml.loc "http://#{@host}#{m[:url]}"
    #     xml.lastmod pretty_date Time.now
    #   end
    # end
    
  end

  File.open( 'sitemap.xml', 'w' ) do |f|
    f.write xml
  end
  
end

#pretty_date(args) ⇒ Object



6
7
8
# File 'lib/sitemaps_tasks.rb', line 6

def pretty_date args
  args.strftime('%Y-%m-%d')
end