ish_lib_engine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/ish_lib_engine/application.js +13 -0
- data/app/assets/javascripts/ish_lib_engine/articles.js +2 -0
- data/app/assets/stylesheets/ish_lib_engine/application.css +15 -0
- data/app/assets/stylesheets/ish_lib_engine/articles.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/ish_lib_engine/application_controller.rb +4 -0
- data/app/controllers/ish_lib_engine/articles_controller.rb +62 -0
- data/app/controllers/ish_lib_engine/manager/cities_controller.rb +95 -0
- data/app/controllers/ish_lib_engine/manager/cities_controller.rb~ +95 -0
- data/app/controllers/ish_lib_engine/manager/features_controller.rb +122 -0
- data/app/controllers/ish_lib_engine/manager/features_controller.rb~ +122 -0
- data/app/controllers/ish_lib_engine/manager/galleries_controller.rb +78 -0
- data/app/controllers/ish_lib_engine/manager/galleries_controller.rb~ +78 -0
- data/app/controllers/ish_lib_engine/manager/manager_controller.rb +31 -0
- data/app/controllers/ish_lib_engine/manager/manager_controller.rb~ +31 -0
- data/app/controllers/ish_lib_engine/manager/newsitems_controller.rb +47 -0
- data/app/controllers/ish_lib_engine/manager/newsitems_controller.rb~ +47 -0
- data/app/controllers/ish_lib_engine/manager/photos_controller.rb +20 -0
- data/app/controllers/ish_lib_engine/manager/photos_controller.rb~ +20 -0
- data/app/controllers/ish_lib_engine/manager/reports_controller.rb +62 -0
- data/app/controllers/ish_lib_engine/manager/reports_controller.rb~ +62 -0
- data/app/controllers/ish_lib_engine/manager/sites_controller.rb +72 -0
- data/app/controllers/ish_lib_engine/manager/sites_controller.rb~ +72 -0
- data/app/controllers/ish_lib_engine/manager/tags_controller.rb +54 -0
- data/app/controllers/ish_lib_engine/manager/tags_controller.rb~ +54 -0
- data/app/controllers/ish_lib_engine/manager/users_controller.rb +13 -0
- data/app/controllers/ish_lib_engine/manager/users_controller.rb~ +13 -0
- data/app/controllers/ish_lib_engine/manager/welcome_controller.rb +8 -0
- data/app/controllers/ish_lib_engine/manager/welcome_controller.rb~ +9 -0
- data/app/helpers/ish_lib_engine/application_helper.rb +4 -0
- data/app/helpers/ish_lib_engine/articles_helper.rb +4 -0
- data/app/models/ability.rb +152 -0
- data/app/models/ability.rb~ +151 -0
- data/app/models/admin_user.rb +113 -0
- data/app/models/app_model2.rb +33 -0
- data/app/models/auth_token.rb +17 -0
- data/app/models/aux_model.rb +22 -0
- data/app/models/cities_user.rb +17 -0
- data/app/models/city.rb +117 -0
- data/app/models/country.rb +13 -0
- data/app/models/day.rb +21 -0
- data/app/models/decoded_auth_token.rb +6 -0
- data/app/models/event.rb +21 -0
- data/app/models/feature.rb +38 -0
- data/app/models/gallery.rb +59 -0
- data/app/models/ish_lib_engine/article.rb +4 -0
- data/app/models/ish_lib_engine/comment.rb +4 -0
- data/app/models/manager.rb +10 -0
- data/app/models/manager_city.rb +4 -0
- data/app/models/manager_feature.rb +4 -0
- data/app/models/manager_gallery.rb +3 -0
- data/app/models/manager_newsitem.rb +5 -0
- data/app/models/manager_photo.rb +3 -0
- data/app/models/manager_report.rb +4 -0
- data/app/models/manager_site.rb +4 -0
- data/app/models/manager_tag.rb +6 -0
- data/app/models/manager_user.rb +3 -0
- data/app/models/manager_venue.rb +4 -0
- data/app/models/message.rb +14 -0
- data/app/models/newsitem.rb +50 -0
- data/app/models/nodeitem.rb +18 -0
- data/app/models/photo.rb +68 -0
- data/app/models/rate_me.rb +13 -0
- data/app/models/report.rb +144 -0
- data/app/models/review.rb +4 -0
- data/app/models/site.rb +83 -0
- data/app/models/tag.rb +78 -0
- data/app/models/user.rb +122 -0
- data/app/models/user_profile.rb +20 -0
- data/app/models/venue.rb +69 -0
- data/app/models/video.rb +48 -0
- data/app/models/welcome.rb +6 -0
- data/app/models/wikitravel_page.rb +19 -0
- data/app/views/application/_flash_messages.haml +24 -0
- data/app/views/application/_flash_messages.haml~ +24 -0
- data/app/views/ish_lib_engine/articles/_form.html.erb +25 -0
- data/app/views/ish_lib_engine/articles/edit.html.erb +6 -0
- data/app/views/ish_lib_engine/articles/index.html.erb +29 -0
- data/app/views/ish_lib_engine/articles/new.html.erb +5 -0
- data/app/views/ish_lib_engine/articles/show.html.erb +14 -0
- data/app/views/layouts/ish_lib_engine/application.html.erb +14 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160501041837_create_ish_lib_engine_articles.rb +10 -0
- data/db/migrate/20160501041940_create_ish_lib_engine_comments.rb +10 -0
- data/lib/addressbookitems_tasks.rb +33 -0
- data/lib/cities_tasks.rb +143 -0
- data/lib/core_extensions.rb +21 -0
- data/lib/features_tasks.rb +17 -0
- data/lib/float.rb +14 -0
- data/lib/galleries_tasks.rb +91 -0
- data/lib/ish_lib_engine.rb +4 -0
- data/lib/ish_lib_engine/engine.rb +5 -0
- data/lib/ish_lib_engine/version.rb +3 -0
- data/lib/reports_tasks.rb +53 -0
- data/lib/sitemaps_tasks.rb +108 -0
- data/lib/sites_tasks.rb +31 -0
- data/lib/string.rb +15 -0
- data/lib/tags_tasks.rb +104 -0
- data/lib/tasks/cities.rake +29 -0
- data/lib/tasks/galleries.rake +19 -0
- data/lib/tasks/ish_lib_engine_tasks.rake +4 -0
- data/lib/tasks/reports.rake +37 -0
- data/lib/tasks/resque.rake +8 -0
- data/lib/tasks/sitemaps.rake +12 -0
- data/lib/tasks/sites.rake +12 -0
- data/lib/tasks/tags.rake +17 -0
- data/lib/tasks/users.rake +14 -0
- data/lib/tasks/venues.rake +13 -0
- data/lib/tasks/videos.rake +18 -0
- data/lib/tasks/wikitravel_pages.rake +40 -0
- data/lib/test_extensions.rb +9 -0
- data/lib/u.rb +34 -0
- data/lib/users_tasks.rb +88 -0
- data/lib/venues_tasks.rb +15 -0
- data/lib/videos_tasks.rb +71 -0
- data/lib/wikitravel_tasks.rb +139 -0
- data/spec/factories/cities.rb +89 -0
- data/spec/factories/galleries.rb +133 -0
- data/spec/factories/photo.rb +20 -0
- data/spec/factories/reports.rb +379 -0
- data/spec/factories/site.rb +26 -0
- data/spec/factories/tag.rb +42 -0
- data/spec/factories/user.rb +87 -0
- data/spec/factories/user_profiles.rb +33 -0
- data/spec/factories/venues.rb +25 -0
- data/spec/factories/videos.rb +38 -0
- data/test/controllers/ish_lib_engine/articles_controller_test.rb +52 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +30 -0
- data/test/dummy/log/development.log +15 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/ish_lib_engine/articles.yml +9 -0
- data/test/fixtures/ish_lib_engine/comments.yml +9 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/ish_lib_engine_test.rb +7 -0
- data/test/models/ish_lib_engine/article_test.rb +9 -0
- data/test/models/ish_lib_engine/comment_test.rb +9 -0
- data/test/test_helper.rb +21 -0
- metadata +361 -0
data/config/routes.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
class AddressbookitemsTasks
|
3
|
+
|
4
|
+
def self.to_mongoid
|
5
|
+
|
6
|
+
p = User.where( :username => 'piousbox' ).first
|
7
|
+
|
8
|
+
olds = SqlAddressbookitems.find :all
|
9
|
+
olds.each do |old|
|
10
|
+
|
11
|
+
if 0 == Addressbookitem.where( :name => old.name ).length
|
12
|
+
|
13
|
+
new = Addressbookitem.new
|
14
|
+
new.name = old.name
|
15
|
+
new.descr = old.descr
|
16
|
+
new.user = p
|
17
|
+
|
18
|
+
new.created_at = old.created_at
|
19
|
+
new.updated_at = old.updated_at
|
20
|
+
|
21
|
+
if new.save
|
22
|
+
puts '+'
|
23
|
+
else
|
24
|
+
puts new.errors.inspect
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/cities_tasks.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
class CitiesTasks
|
3
|
+
|
4
|
+
# include Rails.application.routes.url_helpers
|
5
|
+
|
6
|
+
def self.to_mongoid
|
7
|
+
old_cities = SqlCity.find :all
|
8
|
+
old_cities.each do |old|
|
9
|
+
new = City.new
|
10
|
+
new.name = old.name
|
11
|
+
new.cityname = old.name_seo
|
12
|
+
# new.descr = old.descr
|
13
|
+
new.x = old.x
|
14
|
+
new.y = old.y
|
15
|
+
new.is_feature = old.is_feature
|
16
|
+
new.created_at = old.created_at
|
17
|
+
new.updated_at = old.updated_at
|
18
|
+
new.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.attach_reports_to_cities
|
23
|
+
old_cities = SqlCity.find :all
|
24
|
+
old_cities.each do |old_city|
|
25
|
+
old_city.reports.each do |old_report|
|
26
|
+
new_report = Report.where( :name_seo => old_report.name_seo ).first
|
27
|
+
if new_report.blank?
|
28
|
+
unless Rails.env.test?
|
29
|
+
puts "this name_seo does not exist:"
|
30
|
+
puts old_report.name_seo
|
31
|
+
end
|
32
|
+
else
|
33
|
+
new_city = City.where( :cityname => old_report.city.name_seo ).first
|
34
|
+
new_report.city = new_city
|
35
|
+
new_report.save
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def refresh_newsitems cityname
|
42
|
+
do_refresh = Proc.new do |city|
|
43
|
+
# reports
|
44
|
+
city.reports.each do |r|
|
45
|
+
existing_newsitem = city.newsitems.where( :name => r.name ).first
|
46
|
+
if existing_newsitem.blank?
|
47
|
+
n = Newsitem.new({ :name => r.name, :link_path => report_path( r, city ), :descr => r.subhead,
|
48
|
+
:username => (r.user || User.new).username })
|
49
|
+
city.newsitems << n
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# galleries
|
54
|
+
city.galleries.each do |g|
|
55
|
+
begin
|
56
|
+
image_path = g.photos[0].photo.url(:thumb)
|
57
|
+
rescue
|
58
|
+
image_path = nil
|
59
|
+
end
|
60
|
+
newsitem = city.newsitems.where( :name => g.name ).first
|
61
|
+
if newsitem.blank?
|
62
|
+
city.newsitems << Newsitem.new({ :name => g.name, :link_path => "http://piousbox.com/en/galleries/show/#{g.galleryname}/0", :descr => g.descr,
|
63
|
+
:username => (g.user || User.new ).username, :image_path => image_path })
|
64
|
+
else
|
65
|
+
newsitem[:link_path] = "http://piousbox.com/en/galleries/show/#{g.galleryname}/0"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# features
|
70
|
+
# I omit that b/c there aren't that many, and new content will overwhelm whatever is there right now.
|
71
|
+
#
|
72
|
+
|
73
|
+
if city.save
|
74
|
+
puts! "City #{city.name} saved."
|
75
|
+
else
|
76
|
+
puts! "There were errors with #{city.name}:"
|
77
|
+
puts city.errors.inspect
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if cityname.blank?
|
82
|
+
City.all.each do |city|
|
83
|
+
do_refresh.call city
|
84
|
+
end
|
85
|
+
else
|
86
|
+
do_refresh.call City.where( :cityname => cityname ).first
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def refresh_features city_name
|
91
|
+
do_refresh = Proc.new do |city|
|
92
|
+
puts! "City #{city.name} has #{city.features.length} features."
|
93
|
+
|
94
|
+
city.features.each do |f|
|
95
|
+
if !f.report.blank?
|
96
|
+
f.name = f.report.name
|
97
|
+
f.subhead = f.report.subhead
|
98
|
+
f.link_path = report_path( f.report, f.report.city )
|
99
|
+
f.save
|
100
|
+
elsif !f.gallery.blank?
|
101
|
+
f.name = f.gallery.name
|
102
|
+
f.link_path = gallery_path( f.gallery )
|
103
|
+
f.save
|
104
|
+
else
|
105
|
+
puts! "A feature is neither a report nor a gallery:"
|
106
|
+
puts f.inspect
|
107
|
+
end
|
108
|
+
end
|
109
|
+
if city.save
|
110
|
+
puts! "City #{city.name} features refreshed."
|
111
|
+
else
|
112
|
+
puts! "There was an error:"
|
113
|
+
puts city.errors
|
114
|
+
end
|
115
|
+
end
|
116
|
+
if city_name.blank?
|
117
|
+
City.all.each do |city|
|
118
|
+
do_refresh.call city
|
119
|
+
end
|
120
|
+
else
|
121
|
+
if City.where( :cityname => city_name ).length > 1
|
122
|
+
puts! 'Warning: more than one city with this cityname'
|
123
|
+
end
|
124
|
+
do_refresh.call City.where( :cityname => city_name ).first
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def report_path( r, city )
|
131
|
+
cityname = city.blank? ? 'undefined' : city.cityname
|
132
|
+
"/en/cities/travel-to/#{cityname}/reports/view/#{r.name_seo}"
|
133
|
+
end
|
134
|
+
|
135
|
+
def gallery_path( g )
|
136
|
+
"/en/galleries/view/#{g.galleryname}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def puts! arg
|
140
|
+
puts "=== === #{arg}"
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#in lib/core_extensions.rb
|
4
|
+
class Hash
|
5
|
+
|
6
|
+
###
|
7
|
+
## So far the shit has been unnecessary
|
8
|
+
###
|
9
|
+
|
10
|
+
#pass single or array of keys, which will be removed, returning the remaining hash
|
11
|
+
def remove!(*keys)
|
12
|
+
keys.each{|key| self.delete(key) }
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
#non-destructive version
|
17
|
+
def remove(*keys)
|
18
|
+
self.dup.remove!(*keys)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
class FeaturesTasks
|
3
|
+
|
4
|
+
def self.titleize
|
5
|
+
# all sites
|
6
|
+
Site.all.each do |site|
|
7
|
+
site.features.all.each_with_index do |feature, idx|
|
8
|
+
new = feature.name.titleize
|
9
|
+
if new != feature.name
|
10
|
+
f = site.features.find(feature.id)
|
11
|
+
f.update_attributes :name => new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/float.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
require 'cgi'
|
3
|
+
require "open-uri"
|
4
|
+
|
5
|
+
class GalleriesTasks
|
6
|
+
|
7
|
+
def self.clean_name_seo
|
8
|
+
galleries = Gallery.find :all
|
9
|
+
galleries.each do |g|
|
10
|
+
Util.clean_name_seo g
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.to_mongoid
|
15
|
+
logfile = 'log/galleries_tasks.log'
|
16
|
+
|
17
|
+
File.open(logfile, 'a') do|f|
|
18
|
+
|
19
|
+
f.puts DateTime.new
|
20
|
+
|
21
|
+
user = User.where( :email => 'piousbox@gmail.com' ).first
|
22
|
+
|
23
|
+
# take all photos
|
24
|
+
old_photos = SqlPhoto.find :all,
|
25
|
+
:conditions => { :is_trash => 0 }
|
26
|
+
f.puts "old photos: #{old_photos.count}"
|
27
|
+
|
28
|
+
old_photos.each do |old_photo|
|
29
|
+
if 0 == Photo.where( :old_id => old_photo.id ).length
|
30
|
+
# create new photo
|
31
|
+
new_photo = Photo.new
|
32
|
+
begin
|
33
|
+
new_photo.photo = open(old_photo.photo.url(:original))
|
34
|
+
rescue; end
|
35
|
+
new_photo.user = user
|
36
|
+
|
37
|
+
# gallery?
|
38
|
+
unless old_photo.gallery_id.blank?
|
39
|
+
|
40
|
+
old_gallery = SqlGallery.find old_photo.gallery_id
|
41
|
+
new_gallery = Gallery.where( :galleryname => old_gallery.name_seo ).first
|
42
|
+
if new_gallery.blank?
|
43
|
+
# create new gallery
|
44
|
+
new_gallery = Gallery.new
|
45
|
+
new_gallery.name = old_gallery.name
|
46
|
+
new_gallery.galleryname = old_gallery.name_seo
|
47
|
+
new_gallery.descr = old_gallery.descr
|
48
|
+
new_gallery.x = old_gallery.x
|
49
|
+
new_gallery.y = old_gallery.y
|
50
|
+
new_gallery.created_at = old_gallery.created_at
|
51
|
+
new_gallery.updated_at = old_gallery.updated_at
|
52
|
+
new_gallery.is_public = old_gallery.is_public
|
53
|
+
new_gallery.is_feature = old_gallery.is_feature
|
54
|
+
begin
|
55
|
+
new_gallery.city = City.where( :cityname => old_gallery.city.name_seo ).first
|
56
|
+
rescue; end
|
57
|
+
new_gallery.user = user
|
58
|
+
new_gallery.save
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
new_photo.gallery = new_gallery
|
64
|
+
new_photo.old_id = old_photo.id
|
65
|
+
new_photo.created_at = old_photo.created_at
|
66
|
+
new_photo.updated_at = old_photo.updated_at
|
67
|
+
unless old_photo.city.blank?
|
68
|
+
new_photo.city = City.where( :cityname => old_photo.city.name_seo ).first
|
69
|
+
end
|
70
|
+
new_photo.descr = "#{old_photo.name} -- "
|
71
|
+
new_photo.descr = "#{new_photo.descr}#{old_photo.descr}"
|
72
|
+
new_photo.is_public = old_photo.is_public
|
73
|
+
f.puts "saving new #{new_photo.old_id}..."
|
74
|
+
f.puts new_photo.save
|
75
|
+
|
76
|
+
old_photo.is_trash = 1
|
77
|
+
old_photo.save
|
78
|
+
|
79
|
+
else
|
80
|
+
f.puts "not updating existing photo #{old_photo.id}"
|
81
|
+
old_photo.is_trash = 1
|
82
|
+
old_photo.save
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'simple-rss'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'htmlentities'
|
6
|
+
require 'string'
|
7
|
+
|
8
|
+
class ReportsTasks
|
9
|
+
|
10
|
+
def self.parse_reuters_technology_rss domain = 'piousbox.com'
|
11
|
+
site = Site.where( :lang => 'en', :domain => domain ).first
|
12
|
+
return false if site.blank?
|
13
|
+
|
14
|
+
feed_addr = 'http://feeds.reuters.com/reuters/technologyNews'
|
15
|
+
rss = SimpleRSS.parse open(feed_addr)
|
16
|
+
# puts! rss.channel.title
|
17
|
+
# puts! rss.channel.link
|
18
|
+
item = rss.items.first
|
19
|
+
|
20
|
+
r = Report.new :name => item.title, :name_seo => item.title.to_simple_string
|
21
|
+
r.descr = HTMLEntities.new.decode( item.description ) + "<br />\nRead full article at <a href=\"#{item.link}\">#{item.link}</a>"
|
22
|
+
# r.tag = Tag.where( :name_seo => 'technology' ).first
|
23
|
+
r.user = User.where( :username => 'anon' ).first
|
24
|
+
flag = r.save
|
25
|
+
if flag
|
26
|
+
# puts "Saved report #{r.name}" unless Rails.env.test
|
27
|
+
|
28
|
+
# for homepage
|
29
|
+
n = Newsitem.new
|
30
|
+
n.report = r
|
31
|
+
|
32
|
+
site.newsitems << n
|
33
|
+
site.save
|
34
|
+
|
35
|
+
else
|
36
|
+
puts!(r.errors.messages)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.empty_trash
|
41
|
+
rs = Report.where( :is_trash => true)
|
42
|
+
rs.each do |r|
|
43
|
+
puts "Removed #{r.name}"
|
44
|
+
r.remove
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def puts! args
|
51
|
+
puts '+++ +++'
|
52
|
+
puts args.inspect
|
53
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'builder'
|
3
|
+
|
4
|
+
class SitemapsTasks < ActionController::Base
|
5
|
+
|
6
|
+
def pretty_date args
|
7
|
+
args.strftime('%Y-%m-%d')
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize args = {}
|
11
|
+
@host = args[:domain]
|
12
|
+
@lang = args[:lang]
|
13
|
+
@verbose = args[:verbose]
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate
|
17
|
+
travel_site = Site.where( :domain => @host, :lang => @lang ).first
|
18
|
+
travel_tag = Tag.mobi
|
19
|
+
|
20
|
+
@reports = Report.or( :site => travel_site )
|
21
|
+
|
22
|
+
# @galleries = Gallery.any_of( :site => travel_site, :tag => travel_tag )
|
23
|
+
@galleries = []
|
24
|
+
|
25
|
+
# @videos = Video.any_of( :site => travel_site, :tag => travel_tag )
|
26
|
+
@videos = []
|
27
|
+
|
28
|
+
# @tags = Tag.where( :site => travel_site )
|
29
|
+
@tags = []
|
30
|
+
|
31
|
+
@cities = City.all
|
32
|
+
|
33
|
+
@venues = Venue.all
|
34
|
+
|
35
|
+
# @users = User.all
|
36
|
+
@users = []
|
37
|
+
|
38
|
+
# @meta = [ { :url => cities_path } ]
|
39
|
+
@meta = []
|
40
|
+
|
41
|
+
#
|
42
|
+
# the (builder) view
|
43
|
+
#
|
44
|
+
xml = Builder::XmlMarkup.new(:indent=>2)
|
45
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
46
|
+
xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
|
47
|
+
|
48
|
+
@reports.each do |report|
|
49
|
+
puts "Report: #{report.name}" if @verbose
|
50
|
+
xml.url do
|
51
|
+
xml.loc "http://#{@host}/#{@lang}/reports/view/#{report.name_seo}"
|
52
|
+
xml.lastmod self.pretty_date report.created_at
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@galleries.each do |g|
|
57
|
+
xml.url do
|
58
|
+
xml.loc "http://#{@host}/#{@lang}/galleries/show/#{g.galleryname}"
|
59
|
+
xml.lastmod pretty_date g.created_at
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
@cities.each do |c|
|
64
|
+
puts "City: #{c.name}" if @verbose
|
65
|
+
xml.url do
|
66
|
+
xml.loc "http://#{@host}/#{@lang}/cities/travel-to/#{c.cityname}"
|
67
|
+
xml.lastmod pretty_date c.created_at
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
@tags.each do |c|
|
72
|
+
xml.url do
|
73
|
+
xml.loc "http://#{@host}/#{@lang}/tags/show/#{c.name_seo}"
|
74
|
+
xml.lastmod pretty_date c.created_at
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
@users.each do |user|
|
79
|
+
xml.url do
|
80
|
+
xml.loc "http://#{@host}/#{@lang}/users/show/#{user.username}"
|
81
|
+
xml.lastmod pretty_date user.created_at
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
@venues.each do |c|
|
86
|
+
puts "Venue: #{c.name}" if @verbose
|
87
|
+
xml.url do
|
88
|
+
xml.loc "http://#{@host}/#{@lang}/venues/show/#{c.name_seo}"
|
89
|
+
xml.lastmod pretty_date c.created_at
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# @meta.each do |m|
|
94
|
+
# xml.url do
|
95
|
+
# xml.loc "http://#{@host}#{m[:url]}"
|
96
|
+
# xml.lastmod pretty_date Time.now
|
97
|
+
# end
|
98
|
+
# end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
File.open( 'sitemap.xml', 'w' ) do |f|
|
103
|
+
f.write xml
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|