Module: Murlsh
- Defined in:
- lib/murlsh/uri_domain.rb,
lib/murlsh/ask.rb,
lib/murlsh/doc.rb,
lib/murlsh/url.rb,
lib/murlsh/auth.rb,
lib/murlsh/markup.rb,
lib/murlsh/plugin.rb,
lib/murlsh/server.rb,
lib/murlsh/install.rb,
lib/murlsh/uri_ask.rb,
lib/murlsh/version.rb,
lib/murlsh/dispatch.rb,
lib/murlsh/m3u_body.rb,
lib/murlsh/openlock.rb,
lib/murlsh/rss_body.rb,
lib/murlsh/time_ago.rb,
lib/murlsh/url_body.rb,
lib/murlsh/atom_body.rb,
lib/murlsh/cat_files.rb,
lib/murlsh/cp_r_safe.rb,
lib/murlsh/enclosure.rb,
lib/murlsh/failproof.rb,
lib/murlsh/feed_body.rb,
lib/murlsh/img_store.rb,
lib/murlsh/json_body.rb,
lib/murlsh/image_list.rb,
lib/murlsh/m3u_server.rb,
lib/murlsh/pop_server.rb,
lib/murlsh/rss_server.rb,
lib/murlsh/url_server.rb,
lib/murlsh/atom_server.rb,
lib/murlsh/build_query.rb,
lib/murlsh/json_server.rb,
lib/murlsh/random_server.rb,
lib/murlsh/podcast_server.rb,
lib/murlsh/search_grammar.rb,
lib/murlsh/url_result_set.rb,
lib/murlsh/delicious_parse.rb,
lib/murlsh/must_revalidate.rb,
lib/murlsh/etag_add_encoding.rb,
lib/murlsh/search_conditions.rb,
lib/murlsh/yaml_ordered_hash.rb,
lib/murlsh/far_future_expires.rb,
lib/murlsh/uri_get_path_query.rb,
lib/murlsh/write_ordered_hash.rb
Overview
URI mixin that adds method to get domain.
Defined Under Namespace
Modules: Doc, FeedBody, ImageList, Markup, SearchGrammar, TimeAgo, URIDomain, URIGetPathQuery, UriAsk, YamlOrderedHash Classes: AtomBody, AtomServer, Auth, Dispatch, Enclosure, EtagAddEncoding, FarFutureExpires, ImgStore, JsonBody, JsonServer, M3uBody, M3uServer, MustRevalidate, Plugin, PodcastServer, PopServer, RandomServer, RssBody, RssServer, SearchConditions, SearchGrammarParser, Server, Url, UrlBody, UrlResultSet, UrlServer
Constant Summary collapse
- MurlshRoot =
File.join(File.dirname(__FILE__), '..', '..')
- VERSION =
'1.9.3'
Class Method Summary collapse
-
.ask(prompt, default = nil) ⇒ Object
Ask the user a question and return the answer.
-
.build_query(h) ⇒ Object
Query string builder.
-
.cat_files(files, sep = nil) ⇒ Object
Concatenate some files and return the result as a string.
-
.cp_r_safe(sources, dest, options) ⇒ Object
Recursive copy from sources to destination but ask before overwriting.
-
.delicious_parse(source) ⇒ Object
Parse a delicious xml export and yield a hash for each bookmark.
-
.failproof(options = {}) ⇒ Object
Catch all exceptions unless options = false.
-
.install(dest_dir) ⇒ Object
Install a murlsh site to a web directory.
-
.openlock(*args) ⇒ Object
Open a file with an exclusive lock.
-
.write_ordered_hash(h, path) ⇒ Object
Sort a hash by key and write it to a file as YAML.
Class Method Details
.ask(prompt, default = nil) ⇒ Object
Ask the user a question and return the answer.
6 7 8 9 10 11 12 13 |
# File 'lib/murlsh/ask.rb', line 6 def ask(prompt, default=nil) default_given = !default.to_s.empty? print "#{prompt} " print "[#{default}] " if default_given answer = $stdin.gets.strip answer = default if answer.empty? and default_given answer end |
.build_query(h) ⇒ Object
Query string builder. Takes hash of query string variables.
6 7 8 |
# File 'lib/murlsh/build_query.rb', line 6 def build_query(h) h.empty? ? '' : '?' + h.map { |k,v| URI.escape("#{k}=#{v}") }.join('&') end |
.cat_files(files, sep = nil) ⇒ Object
Concatenate some files and return the result as a string.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/murlsh/cat_files.rb', line 6 def cat_files(files, sep=nil) result = '' files.each do |fname| open(fname) do |h| while (line = h.gets) do; result << line; end result << sep if sep end end result end |
.cp_r_safe(sources, dest, options) ⇒ Object
Recursive copy from sources to destination but ask before overwriting.
Options are passed into FileUtils.mkdir_p FileUtils.copy.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/murlsh/cp_r_safe.rb', line 12 def cp_r_safe(sources, dest, ) sources.each do |source| new = File.join(dest, File.split(File.(source)).last) if File.directory?(source) FileUtils.mkdir_p(new, ) cp_r_safe(Dir.entries(source). reject { |f| %w{. ..}.include?(f) }. map { |f| File.join(source, f) }, new, ) else answer = if File.exists?(new) Murlsh.ask("#{new} exists. Overwrite?", 'n') else 'y' end FileUtils.copy(source, new, ) if answer == 'y' end end end |
.delicious_parse(source) ⇒ Object
Parse a delicious xml export and yield a hash for each bookmark.
To export your delicious bookmarks:
curl https://user:[email protected]/v1/posts/all > delicious.xml
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/murlsh/delicious_parse.rb', line 15 def delicious_parse(source) doc = Nokogiri::XML(open(source)) doc.xpath('//post').each do |p| result = {} p.each { |k,v| result[k.to_sym] = v } result[:tag] = result[:tag].split result[:time] = Time.parse(result[:time]) # extract via information from extended result[:via] = result[:extended].chomp(')')[%r{via\s+([^\s]+)}, 1] result[:via_url] = begin if result[:via] and %w{http https}.include?(URI(result[:via]).scheme.to_s.downcase) result[:via] end rescue URI::InvalidURIError end yield result end end |
.failproof(options = {}) ⇒ Object
Catch all exceptions unless options = false.
6 7 8 9 10 11 12 |
# File 'lib/murlsh/failproof.rb', line 6 def failproof(={}) begin yield rescue Exception raise unless .fetch(:failproof, true) end end |
.install(dest_dir) ⇒ Object
Install a murlsh site to a web directory.
Copies files that are different per-site to make a site instance.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/murlsh/install.rb', line 14 def install(dest_dir) Murlsh.cp_r_safe( %w{ .htaccess Rakefile config/ config.ru config.yaml db/ plugins/ public/ }.map { |x| File.join(MurlshRoot, x) }, dest_dir, :verbose => true) FileUtils.mkdir_p(File.join(dest_dir, 'tmp'), :verbose => true) end |
.openlock(*args) ⇒ Object
Open a file with an exclusive lock.
6 7 8 9 10 |
# File 'lib/murlsh/openlock.rb', line 6 def openlock(*args) open(*args) do |f| f.flock(File::LOCK_EX) ; yield f ; f.flock(File::LOCK_UN) end end |
.write_ordered_hash(h, path) ⇒ Object
Sort a hash by key and write it to a file as YAML.
8 9 10 11 12 13 14 15 |
# File 'lib/murlsh/write_ordered_hash.rb', line 8 def write_ordered_hash(h, path) h.extend(Murlsh::YamlOrderedHash) h.each_value do |v| v.extend(Murlsh::YamlOrderedHash) if v.is_a?(Hash) end open(path, 'w') { |f| YAML.dump(h, f) } end |