Module: Trutag
- Defined in:
- lib/tRuTag_full.rb,
lib/tRuTag.rb
Overview
I’ve separated this out from TagCloudMaker since I’ve split the functionality. We have the lightweight classes needed to generate the cloud. These can be used on a website or locally. That is in tRuTag.rb. tRuTag_full contains the additional functionality to create the full html file
Class Method Summary collapse
- .asks(question) ⇒ Object
- .asksb(question) ⇒ Object
- .buildpage(parray, p4p, style) ⇒ Object
- .config_it ⇒ Object
- .create_tag_cloud(params, p4p) ⇒ Object
- .create_tag_cloud_for_rails_site(params) ⇒ Object
-
.find_home ⇒ Object
Thank you Ruby Gems and ruby-talk.
- .get_params_from_yaml(forceconfig) ⇒ Object
- .get_profile(classname) ⇒ Object
- .getAbout(div_id) ⇒ Object
- .loggit(severity, message) ⇒ Object
- .make_rails_cloud_from_tag_hash(tbin, target) ⇒ Object
- .yes(param) ⇒ Object
Class Method Details
.asks(question) ⇒ Object
154 155 156 157 |
# File 'lib/tRuTag_full.rb', line 154 def Trutag::asks(question) print %{#{question}: } gets.chomp end |
.asksb(question) ⇒ Object
159 160 161 162 |
# File 'lib/tRuTag_full.rb', line 159 def Trutag::asksb(question) print %{#{question}? (y/n) : } Trutag::yes(gets.chomp) end |
.buildpage(parray, p4p, style) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/tRuTag_full.rb', line 16 def Trutag::buildpage(parray, p4p, style) parray['target']={ 'type' => 'target', 'style' => style } # make the HTML file output = Trutag::create_tag_cloud(parray, p4p) maker=TagCloudPageMaker.new maker.make(output['cloud'], output['space'], output['url'], output['post'], output['sitename']) end |
.config_it ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/tRuTag_full.rb', line 104 def Trutag::config_it params=Hash.new params['websites']=Hash.new if Trutag::asksb("Welcome to tRuTag Config. Continue") websites=YAML::load(File.open($websites_file)) params['store_pwd'] = Trutag::asksb("Store website passwords (cleartext) in a config file in your home directory") params['use_int'] = Trutag::asksb("Use international sites") params['output_to_file'] = Trutag::asksb("Save output as file?") if params['output_to_file'] params['output_file'] = Trutag::asks("File and Path") end websites.each_value { |v| if v.fetch('mode', 0) == 1 && (params['use_int'] || !v.has_key?('international')) if Trutag::asksb(%{Retrieve data from #{v['sitename']}}) userdata=Hash.new if v.fetch('user', 0)==1 userdata['username'] = Trutag::asks(%{#{v['sitename']} username}) end if v.fetch('eml', 0)==1 userdata['email'] = Trutag::asks(%{#{v['sitename']} email address}) end if v.fetch('auth', 0)==1 if params['store_pwd'] == TRUE userdata['pwd'] = Trutag::asks(%{#{v['sitename']} password}) else userdata['prompt'] = 1 end end params['websites'][v['type']] = userdata end end } if Trutag::asksb("Save") File.open(@cfile ,'w+') {|fh| fh.print params.to_yaml} print %{Saved.\n} end end params end |
.create_tag_cloud(params, p4p) ⇒ Object
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 |
# File 'lib/tRuTag_full.rb', line 24 def Trutag::create_tag_cloud(params, p4p) tbin=Hash.new() output = Hash.new() sites = YAML::load(File.open($websites_file)) params.each { | k, i | if k != 'target' then #This should be a hash of site data such as : #{ 'type' => 'Delicious', 'username' => 'foo', 'pwd' => 'bar' } if !sites.has_key?(k) loggit(2, %{no entry for #{k} in websites.yml}) end i.update(sites[k]) if i.fetch('prompt', 0) == 1 if ARGV.empty? print %{Please enter password for #{i['sitename']}: } i['pwd']=gets.chomp else i['pwd']=ARGV.shift end end i['tbin']=tbin Profile.new(i) end } # Lets add our non input sites to the arrays space_replacement_array=Array.new() tag_url_array=Array.new() tag_url_array_post=Array.new() sitename_array=Array.new() sites.each { | k, v | space_replacement_array.push v.fetch('space_replacement', '%20') tag_url_array.push("http://" + v.fetch('url', %{www.#{v['sitename']}.com})+v.fetch('all_tags_path', '/tag/')) tag_url_array_post.push v.fetch('all_tags_path_post_tag', '') sitename_array.push v.fetch('sitename', 'Site?') } # Now we should have a hash of all of our tags. Let make it happen! output['space'] = space_replacement_array output['url'] = tag_url_array output['post'] = tag_url_array_post output['sitename'] = sitename_array output['cloud'] = Trutag.make_rails_cloud_from_tag_hash(tbin, params['target']) output end |
.create_tag_cloud_for_rails_site(params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tRuTag.rb', line 37 def Trutag::create_tag_cloud_for_rails_site(params) tbin=Hash.new() sites = YAML::load(File.open($websites_file)) params.each { | k, i | if k != 'target' then #This should be a hash of site data such as : #{ 'type' => 'Delicious', 'username' => 'foo', 'pwd' => 'bar' } if !sites.has_key?(k) loggit(2, %{no entry for #{k} in websites.yml}) end i.update(sites[k]) i['tbin']=tbin Profile.new(i) end } # Now we should have a hash of all of our tags. Let make it happen! Trutag.make_rails_cloud_from_tag_hash(tbin, params['target']) end |
.find_home ⇒ Object
Thank you Ruby Gems and ruby-talk
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/tRuTag_full.rb', line 75 def Trutag::find_home ['HOME', 'USERPROFILE'].each do |homekey| return ENV[homekey] if ENV[homekey] end if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}" end begin File.("~") rescue Exception => ex if File::ALT_SEPARATOR "C:/" else "/" end end end |
.get_params_from_yaml(forceconfig) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/tRuTag_full.rb', line 93 def Trutag::get_params_from_yaml(forceconfig) @cfile =Trutag::find_home+"/"+$configfile if !forceconfig && File::exists?(@cfile) cnf=YAML::load(File.open(@cfile)) else cnf=config_it end cnf end |
.get_profile(classname) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/tRuTag.rb', line 29 def Trutag::get_profile(classname) if classname == "" || classname == nil classname ='Technorati' end Profile.new({ "type" => classname }) end |
.getAbout(div_id) ⇒ Object
65 66 67 |
# File 'lib/tRuTag.rb', line 65 def Trutag::getAbout(div_id) TagCloudMaker.about(div_id) end |
.loggit(severity, message) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/tRuTag.rb', line 69 def Trutag::loggit(severity, ) severities=['message', 'warning', 'error'] if != "" $stderr.print %{tRuTag #{severities[severity]}: #{}\n\tDescription:#{$!}\n} else $stderr.print %{tRuTag #{severities[severity]}: #{$!}\n} end end |
.make_rails_cloud_from_tag_hash(tbin, target) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/tRuTag.rb', line 57 def Trutag::make_rails_cloud_from_tag_hash(tbin, target) output = "" tbin.each { | key, value | output << TagCloudMaker.(key, value, target)} output end |
.yes(param) ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/tRuTag_full.rb', line 164 def Trutag::yes(param) returnval=FALSE if param != nil returnval=(param.downcase=="y") end returnval end |