gorgeous 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/LICENSE +18 -0
  2. data/README.md +73 -1
  3. data/bin/gorgeous +5 -1
  4. data/lib/gorgeous.rb +11 -2
  5. metadata +24 -43
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2011 Mislav Marohnić
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
+ # Filthy → gorgeous
2
+
3
+ Convert between formats.
4
+
1
5
  Usage:
2
6
 
3
7
  gorgeous [-i] [-F <in-format>] [-T <out-format>] [-q <query>] [-o <destination>] FILE ...
4
8
 
5
- This utility converts data between different formats.
9
+ This utility converts data between different formats.
6
10
  Formats are one of: json, xml, yaml, ruby, email, url
7
11
 
8
12
  Input can be read from STDIN as well as files given on the command-line.
@@ -20,3 +24,71 @@ Query format:
20
24
  "/items/comments[1]/text" -- 2nd comment body of each item
21
25
  "/items[-1]/user/full_name" -- name of user for last item
22
26
  "//user/username" -- usernames of all users anywhere in the document
27
+
28
+ ## Prerequisites
29
+
30
+ It's recommended that you install all of these ruby libraries. They are only loaded when processing specific formats.
31
+
32
+ * **nokogiri** for xml
33
+ * **yajl-ruby** for json
34
+ * **activesupport** (for various stuff)
35
+ * **rack** for url
36
+ * **mail** for email
37
+
38
+ All together now:
39
+
40
+ $ gem install nokogiri yajl-ruby activesupport rack mail
41
+
42
+ ## Examples
43
+
44
+ Pipe in standard input:
45
+
46
+ # auto-detects input as being JSON, displays prettified output:
47
+ $ curl -s api.twitter.com/1/statuses/show/40453487309361153.json | gorgeous
48
+
49
+ # covert from JSON to YAML
50
+ $ curl -s <url> | gorgeous -T yaml
51
+
52
+ # extract Twitter avatar from tweet as text
53
+ $ curl -s <url> | gorgeous -T txt -q /user/profile_image_url
54
+
55
+ Prettify a file in place:
56
+
57
+ # auto-detects format by extension, prettifies and overwrites the file:
58
+ $ gorgeous -i some-data.json
59
+
60
+ # convert some data to YAML
61
+ $ gorgeous -i -F json -T yaml some-data
62
+
63
+ Prettify some HTML (gorgeous calls it "xml"):
64
+
65
+ $ curl -s www.1112.net/lastpage.html | gorgeous -F xml
66
+
67
+ Prettify content in clipboard (on a Mac):
68
+
69
+ $ pbpaste | gorgeous | pbcopy
70
+
71
+ # convert from YAML to ruby format and copy to clipboard
72
+ $ gorgeous fixture.yml -T ruby | pbcopy
73
+
74
+ Parse query strings and URL-encoded POST payloads:
75
+
76
+ $ echo 'sourceid=chrome&ie=UTF-8&q=filthy+gorgeous' | gorgeous -T yaml
77
+ ---
78
+ sourceid: chrome
79
+ q: filthy gorgeous
80
+ ie: UTF-8
81
+
82
+ Parse emails:
83
+
84
+ # extract prettified HTML part of the email:
85
+ $ cat email.raw | gorgeous -F email -T xml
86
+
87
+ # extract decoded text part of the email:
88
+ $ cat email.raw | gorgeous -F email -T txt
89
+
90
+ # get email headers as JSON:
91
+ $ cat email.raw | gorgeous -F email -T json
92
+
93
+ # get only the email subject:
94
+ $ cat email.raw | gorgeous -F email -T txt -q /subject
data/bin/gorgeous CHANGED
@@ -81,7 +81,11 @@ if output_format == :ruby
81
81
  require 'pp'
82
82
  output = input.data.pretty_inspect
83
83
  elsif output_format == :json
84
- require 'yajl/json_gem'
84
+ begin
85
+ require 'yajl/json_gem'
86
+ rescue LoadError
87
+ require 'json'
88
+ end
85
89
  output = JSON.pretty_generate input.data
86
90
  elsif output_format == :yaml
87
91
  require 'yaml'
data/lib/gorgeous.rb CHANGED
@@ -38,7 +38,12 @@ class Gorgeous
38
38
  end
39
39
  }
40
40
  header_value = lambda { |name|
41
- field = email.header[name] and field.value.to_s
41
+ field = email.header[name]
42
+ if Array === field
43
+ field.map { |f| f.value.to_s }
44
+ elsif field
45
+ field.value.to_s
46
+ end
42
47
  }
43
48
  decoded_value = lambda { |name|
44
49
  field = email.header[name]
@@ -120,7 +125,11 @@ class Gorgeous
120
125
  require 'active_support/core_ext/hash/conversions'
121
126
  Hash.from_xml(to_s)
122
127
  when :json
123
- require 'yajl/json_gem'
128
+ begin
129
+ require 'yajl/json_gem'
130
+ rescue LoadError
131
+ require 'json'
132
+ end
124
133
  JSON.parse to_s
125
134
  when :yaml
126
135
  require 'yaml'
metadata CHANGED
@@ -1,70 +1,51 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gorgeous
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
11
6
  platform: ruby
12
- authors:
13
- - "Mislav Marohni\xC4\x87"
7
+ authors:
8
+ - Mislav Marohnić
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-15 00:00:00 +01:00
19
- default_executable:
12
+ date: 2011-12-16 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
14
  description:
23
15
  email: mislav.marohnic@gmail.com
24
- executables:
16
+ executables:
25
17
  - gorgeous
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - bin/gorgeous
32
22
  - lib/gorgeous.rb
33
23
  - lib/pretty.xslt
34
24
  - README.md
35
- has_rdoc: false
36
- homepage: http://github.com/mislav/gorgeous
25
+ - LICENSE
26
+ homepage: https://github.com/mislav/gorgeous
37
27
  licenses: []
38
-
39
28
  post_install_message:
40
29
  rdoc_options: []
41
-
42
- require_paths:
30
+ require_paths:
43
31
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
32
+ required_ruby_version: !ruby/object:Gem::Requirement
45
33
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 3
50
- segments:
51
- - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
62
44
  requirements: []
63
-
64
45
  rubyforge_project:
65
- rubygems_version: 1.5.0
46
+ rubygems_version: 1.8.12
66
47
  signing_key:
67
48
  specification_version: 3
68
- summary: Convert between different data formats
49
+ summary: Convert between different data formats; prettify JSON, HTML and XML
69
50
  test_files: []
70
-
51
+ has_rdoc: