rogerleite-gedit-snippets-tool 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ h2. DESCRIPTION AND MOTIVATION:
2
+
3
+ Tool to generate cheat sheet of "gedit's snippets":http://live.gnome.org/Gedit/Plugins/Snippets .
4
+
5
+ Gedit's snippets are personal files that you can change any time, and now, you can have your "custom" cheat sheet any time too.
6
+
7
+ h2. INSTALLATION:
8
+
9
+ @sudo gem install rogerleite-gedit-snippets-tool -s http://gems.github.com@
10
+
11
+ h2. USAGE
12
+
13
+ To generate a cheat sheet with all your snippets: <br>
14
+ @gedit-snippets-tool -cs > ~/mycheatsheet.xhtml@
15
+
16
+ To generate a cheat sheet with all your snippets that starts with "ruby": <br>
17
+ @gedit-snippets-tool -cs ruby* > ~/mycheatsheet.xhtml@
18
+
19
+ After that, you can access you new brand cheat sheet at your home folder.
20
+
21
+ **IMPORTANT:** gedit-snippets-tool reads your "{home-folder}/.gnome2/gedit/snippets/" folder. I noticed that default use of snippet plugin uses "/usr/share/gedit-2/plugins/snippets/" folder. So please, with you want to generate your cheat sheets, copy the contents from "/usr/share/gedit-2/plugins/snippets/" to "{home-folder}/.gnome2/gedit/snippets/". Thanks!
22
+
23
+ h2. LICENSE:
24
+
25
+ (The MIT License)
26
+
27
+ Copyright (c) 2008 FIX
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining
30
+ a copy of this software and associated documentation files (the
31
+ 'Software'), to deal in the Software without restriction, including
32
+ without limitation the rights to use, copy, modify, merge, publish,
33
+ distribute, sublicense, and/or sell copies of the Software, and to
34
+ permit persons to whom the Software is furnished to do so, subject to
35
+ the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be
38
+ included in all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
41
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
44
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
45
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47
+
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rubygems/specification'
3
+ require 'rake'
4
+ require 'rake/gempackagetask'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "gedit-snippets-tool"
8
+ GEM_VERSION = "0.2.2"
9
+ SUMMARY = "Tool to generate cheat sheet of gedit's snippets"
10
+ AUTHOR = "Roger Leite"
11
+ EMAIL = "roger.barreto@gmail.com"
12
+ HOMEPAGE = "http://1up4dev.org"
13
+
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = GEM
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.summary = SUMMARY
20
+ s.require_paths = ['bin', 'lib']
21
+ s.files = FileList['bin/*', 'lib/**/*.rb', 'template/**/*.eruby', '[A-Z]*'].to_a
22
+ s.executables = ["gedit-snippets-tool"]
23
+
24
+ s.author = AUTHOR
25
+ s.email = EMAIL
26
+ s.homepage = HOMEPAGE
27
+
28
+ s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
29
+
30
+ s.add_dependency(%q<erubis>, [">= 2.6.4"])
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new do |t|
34
+ t.spec_files = FileList['spec/**/*_spec.rb']
35
+ t.spec_opts = %w(-fs --color)
36
+ end
37
+
38
+ Rake::GemPackageTask.new(spec) do |pkg|
39
+ pkg.gem_spec = spec
40
+ end
41
+
42
+ desc "Install the gem locally"
43
+ task :install => [:package] do
44
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
45
+ end
46
+
47
+ desc "Create a gemspec file"
48
+ task :make_spec do
49
+ File.open("#{GEM}.gemspec", "w") do |file|
50
+ file.puts spec.to_ruby
51
+ end
52
+ end
53
+
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gedit_snippets_tool'
5
+
6
+ args = ARGV.dup
7
+ ARGV.clear
8
+
9
+ commands = GeditSnippetsTool::Commands.new
10
+ commands.execute args
11
+
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/snippet")
2
+ require 'erubis'
3
+
4
+ module GeditSnippetsTool
5
+
6
+ VERSION = '0.2.2'
7
+
8
+ class Commands
9
+
10
+ def execute(args)
11
+ command = args.shift.strip rescue '--help'
12
+
13
+ if %w(-h --help).include? command
14
+ show_help
15
+ elsif %w(-v --version).include? command
16
+ puts "#{File.basename($0)} #{VERSION}"
17
+ elsif %w(-cs --cheat-sheet).include? command
18
+ generate_cheat_sheet args[0]
19
+ else
20
+ puts "Unknow command '#{command}'"
21
+ puts ""
22
+ show_help
23
+ end
24
+ end
25
+
26
+ def show_help
27
+ puts "Usage: #{File.basename($0)} [OPTION]"
28
+ puts "Tool to generate cheat sheet of gedit's snippets"
29
+ puts ""
30
+ puts "Valid options:"
31
+ puts "-cs, --cheat-sheet\tcreate cheat sheet of yours gedit's snippets"
32
+ puts "-h, --help\tshow this help"
33
+ puts "-v, --version\tshow #{File.basename($0)}'s version"
34
+ puts ""
35
+ end
36
+
37
+ def generate_cheat_sheet(snippet_name=nil)
38
+
39
+ hash_of_snippets = Snippet.all(snippet_name)
40
+
41
+ input = File.read(File.expand_path(File.dirname(__FILE__) + "/../template/template.eruby"))
42
+ eruby = Erubis::EscapedEruby.new(input) # create Eruby object
43
+
44
+ ## create context object
45
+ ## (key means var name, which may be string or symbol.)
46
+ context = {
47
+ :hash_of_snippets => hash_of_snippets
48
+ }
49
+
50
+ puts eruby.evaluate(context) # get result
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,51 @@
1
+ require 'rexml/document'
2
+
3
+ class Snippet
4
+
5
+ attr_accessor :tag, :description, :text, :accelerator
6
+
7
+ def self.all(snippet_name=nil)
8
+ snippet_name = '*' if snippet_name.nil?
9
+ path_to_xmls = ENV['HOME'] + "/.gnome2/gedit/snippets/#{snippet_name}.xml"
10
+
11
+ snippets = {}
12
+ Dir.glob(path_to_xmls).each do |file|
13
+ doc = REXML::Document.new( File.new(file) )
14
+ file_name = File.basename(file, '.xml')
15
+ snippets[file_name] = load_by_xml(doc)
16
+ end
17
+
18
+ snippets
19
+ end
20
+
21
+ def self.load_by_xml xml_snippet
22
+ snippets = []
23
+ xml_snippet.root.each_element('//snippet') do |snippet_element|
24
+ snippets << parse(snippet_element)
25
+ end
26
+ snippets
27
+ end
28
+
29
+ private
30
+
31
+ def self.parse(snippet_element)
32
+ new_snippet = Snippet.new
33
+ #puts snippet_element #help to debug :(
34
+ new_snippet.tag = snippet_element.elements['tag'].text unless snippet_element.elements['tag'].nil?
35
+ new_snippet.description = snippet_element.elements['description'].text unless snippet_element.elements['description'].nil?
36
+
37
+ text_element = snippet_element.elements['text']
38
+ if not text_element.nil?
39
+ new_snippet.text = text_element.cdatas.first
40
+ end
41
+
42
+ accelerator_element = snippet_element.elements['accelerator']
43
+ if not accelerator_element.nil?
44
+ new_snippet.accelerator = accelerator_element.cdatas.first
45
+ end
46
+
47
+ new_snippet
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,55 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>Cheat Sheet Gedit Snippets</title>
6
+ <style>
7
+ span {
8
+ border-bottom: 1px solid;
9
+ text-align: center;
10
+ font-size: 3em;
11
+ }
12
+
13
+ table {
14
+ width: 768px;
15
+ }
16
+
17
+ tr.even {
18
+ }
19
+
20
+ tr.odd {
21
+ background: lightgray;
22
+ }
23
+
24
+ td {
25
+ border-bottom: 1px solid;
26
+ }
27
+ </style>
28
+ </head>
29
+ <body>
30
+
31
+ <br/>
32
+
33
+ <% @hash_of_snippets.each_pair do |snippet_name, snippets| %>
34
+ <span><%= snippet_name %></span>
35
+ <table>
36
+ <% snippets.each_with_index do |snippet, index| %>
37
+ <tr class="<%= index % 2 == 0 ? 'even' : 'odd' %>">
38
+ <td>
39
+ <%= snippet.description %> (<b><%= snippet.tag %></b>) <br/>
40
+ <blockquote>
41
+ <%= snippet.text %>
42
+ </blockquote>
43
+ <% if not snippet.accelerator.nil? %>
44
+ <br/> accelerator: <%= snippet.accelerator %>
45
+ <% end %>
46
+ </td>
47
+ </tr>
48
+ <% end %>
49
+ </table>
50
+ <br/>
51
+ <% end %>
52
+
53
+ </body>
54
+ </html>
55
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rogerleite-gedit-snippets-tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Roger Leite
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-30 00:00:00 -07:00
13
+ default_executable: gedit-snippets-tool
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: erubis
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.6.4
24
+ version:
25
+ description:
26
+ email: roger.barreto@gmail.com
27
+ executables:
28
+ - gedit-snippets-tool
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - bin/gedit-snippets-tool
35
+ - lib/gedit_snippets_tool.rb
36
+ - lib/snippet.rb
37
+ - template/template.eruby
38
+ - Rakefile
39
+ - README.textile
40
+ has_rdoc: false
41
+ homepage: http://1up4dev.org
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - bin
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: gedit-snippets-tool
63
+ rubygems_version: 1.2.0
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: Tool to generate cheat sheet of gedit's snippets
67
+ test_files: []
68
+