snipcheat 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/bin/snipcheat +4 -0
- data/lib/snipcheat/output.rb +30 -0
- data/lib/snipcheat/snippet.rb +31 -0
- data/lib/snipcheat/snippet_dir.rb +23 -0
- data/lib/snipcheat/task.rb +34 -0
- data/lib/snipcheat/version.rb +3 -0
- data/lib/snipcheat.rb +5 -0
- data/lib/templates/simple.html.haml +16 -0
- data/snipcheat.gemspec +25 -0
- data/spec/fixtures/no.snippet +0 -0
- data/spec/fixtures/sample.sublime-snippet +6 -0
- data/spec/output_spec.rb +17 -0
- data/spec/snippet_dir_spec.rb +34 -0
- data/spec/snippet_spec.rb +15 -0
- data/spec/spec_helper.rb +18 -0
- metadata +136 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tadas Tamosauskas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Snipcheat
|
2
|
+
|
3
|
+
Snipcheat takes a directory with sublime snippets and generates you a cheatsheet file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install snipcheat
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ snipcheat generate -d Packages/Rails -o ~/rails_cheatsheet.html
|
12
|
+
|
13
|
+
## Contributing
|
14
|
+
|
15
|
+
Contributions are very welcome. Please consider the list of things that could improve the gem:
|
16
|
+
|
17
|
+
* Better/more CSS styles for output
|
18
|
+
* Live search
|
19
|
+
* Ability to generate a website with nested lists of cheatsheets
|
20
|
+
|
21
|
+
### How to contribute
|
22
|
+
|
23
|
+
1. Fork it
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create new Pull Request
|
data/bin/snipcheat
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'haml'
|
2
|
+
|
3
|
+
module Snipcheat
|
4
|
+
class Output
|
5
|
+
def initialize(snippets, out_file)
|
6
|
+
@snippets = snippets
|
7
|
+
@out_file = out_file
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
f = File.open(@out_file, 'w') do |f|
|
12
|
+
f.write(to_s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
engine = Haml::Engine.new(template_string)
|
18
|
+
out = engine.render(Object.new, snippets: @snippets)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def template_string
|
24
|
+
f = File.open(File.join(File.dirname(__FILE__), '..', 'templates', 'simple.html.haml'))
|
25
|
+
f.read
|
26
|
+
ensure
|
27
|
+
f.close
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'crack/xml'
|
2
|
+
module Snipcheat
|
3
|
+
class Snippet
|
4
|
+
attr_reader :scope, :content, :description, :tab_trigger
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
load
|
8
|
+
end
|
9
|
+
|
10
|
+
def load
|
11
|
+
mash.each do |key, value|
|
12
|
+
underscorized = key.to_s
|
13
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
14
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
15
|
+
.tr("-", "_")
|
16
|
+
.downcase
|
17
|
+
instance_variable_set("@#{underscorized}", value.to_s)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def mash
|
23
|
+
@_mash ||= begin
|
24
|
+
f = File.open(@path)
|
25
|
+
Crack::XML.parse(f.read)['snippet']
|
26
|
+
ensure
|
27
|
+
f.close
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'snipcheat/snippet'
|
2
|
+
|
3
|
+
module Snipcheat
|
4
|
+
class SnippetDir
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def empty?
|
10
|
+
filenames.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
def snippets
|
14
|
+
@_snippets ||= filenames.map{ |fn| Snippet.new(File.join(@path, fn)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def filenames
|
18
|
+
@_filenames ||= Dir.new(@path).select{ |x|
|
19
|
+
x.end_with? '.sublime-snippet'
|
20
|
+
}.compact
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'snipcheat/snippet_dir'
|
2
|
+
require 'snipcheat/output'
|
3
|
+
|
4
|
+
module Snipcheat
|
5
|
+
class Task < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
class_option :verbose, type: :boolean, aliases: '-v'
|
9
|
+
method_option :dir, type: :string, aliases: '-d', desc: "Input directory containing .sublime-snippet files", required: true
|
10
|
+
method_option :out, type: :string, aliases: '-o', desc: "Output file. eg ~/ruby-cheatsheet.html. Defaults to cheatsheet.html"
|
11
|
+
desc "generate", "Generate a cheat sheet file given --dir and -out"
|
12
|
+
def generate
|
13
|
+
vsay "Looking for snippets in #{options[:dir]}"
|
14
|
+
snippet_dir = SnippetDir.new(options[:dir])
|
15
|
+
if snippet_dir.empty?
|
16
|
+
say "No snippets found in #{options[:dir]}"
|
17
|
+
return
|
18
|
+
else
|
19
|
+
vsay "Found: #{snippet_dir.filenames.join(', ')}"
|
20
|
+
out = options[:out] || 'cheatsheet.html'
|
21
|
+
vsay "Writing to #{out}..."
|
22
|
+
Output.new(snippet_dir.snippets, out).write
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def vsay(message)
|
29
|
+
if options[:verbose]
|
30
|
+
say message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/snipcheat.rb
ADDED
data/snipcheat.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'snipcheat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "snipcheat"
|
8
|
+
gem.version = Snipcheat::VERSION
|
9
|
+
gem.authors = ["Tadas Tamosauskas"]
|
10
|
+
gem.email = ["tadas@pdfcv.com"]
|
11
|
+
gem.description = %q{Generate a cheatsheet HTML given a directory with Sublime Text snippets}
|
12
|
+
gem.summary = %q{Sublime Text 2 snippet cheat-sheet generator}
|
13
|
+
gem.homepage = "https://github.com/tadast/snipcheat"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'crack'
|
21
|
+
gem.add_dependency 'thor'
|
22
|
+
gem.add_dependency 'haml'
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rspec'
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<snippet>
|
2
|
+
<content><![CDATA[${TM_RAILS_TEMPLATE_START_RUBY_EXPR}stylesheet_link_tag {1::all}${2:, media: ${3:"all"}}${TM_RAILS_TEMPLATE_END_RUBY_EXPR}]]></content>
|
3
|
+
<tabTrigger>slt</tabTrigger>
|
4
|
+
<scope>text.html.ruby</scope>
|
5
|
+
<description>stylesheet_link_tag</description>
|
6
|
+
</snippet>
|
data/spec/output_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Snipcheat
|
4
|
+
describe Output do
|
5
|
+
describe "#to_s" do
|
6
|
+
it "has all the snippet attributes" do
|
7
|
+
snippets = [double(content: 'xyz', tab_trigger: 'ttr', description: 'magic', scope: 'all.files')]
|
8
|
+
out = Output.new(snippets, :path).to_s
|
9
|
+
|
10
|
+
out.should match 'xyz'
|
11
|
+
out.should match 'ttr'
|
12
|
+
out.should match 'magic'
|
13
|
+
out.should match 'all.files'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Snipcheat
|
4
|
+
describe SnippetDir do
|
5
|
+
let(:fixtures_dir){ SnippetDir.new(File.join(File.dirname(__FILE__), "fixtures")) }
|
6
|
+
|
7
|
+
describe "#empty?" do
|
8
|
+
it "is false for the fixtures dir" do
|
9
|
+
fixtures_dir.should_not be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it "is true for the spec folder" do
|
13
|
+
dir = SnippetDir.new(File.join(File.dirname(__FILE__), "..", ".."))
|
14
|
+
dir.should be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#snippets" do
|
19
|
+
it "is an array of Snippets" do
|
20
|
+
fixtures_dir.snippets.first.should be_a Snippet
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#filenames" do
|
25
|
+
it "finds sample snippet" do
|
26
|
+
fixtures_dir.filenames.should include('sample.sublime-snippet')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not include no snippet" do
|
30
|
+
fixtures_dir.filenames.should_not include('no.snippet')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Snipcheat
|
4
|
+
describe Snippet do
|
5
|
+
it "reads all properties from an xml file" do
|
6
|
+
snippet_path = File.join(File.dirname(__FILE__), "fixtures", "sample.sublime-snippet")
|
7
|
+
snippet = Snippet.new(snippet_path)
|
8
|
+
|
9
|
+
snippet.content.should be_a String
|
10
|
+
snippet.tab_trigger.should eq 'slt'
|
11
|
+
snippet.scope.should eq 'text.html.ruby'
|
12
|
+
snippet.description.should eq 'stylesheet_link_tag'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'snipcheat'
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
5
|
+
# loaded once.
|
6
|
+
#
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snipcheat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tadas Tamosauskas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: crack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: thor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: haml
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Generate a cheatsheet HTML given a directory with Sublime Text snippets
|
79
|
+
email:
|
80
|
+
- tadas@pdfcv.com
|
81
|
+
executables:
|
82
|
+
- snipcheat
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rspec
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- bin/snipcheat
|
92
|
+
- lib/snipcheat.rb
|
93
|
+
- lib/snipcheat/output.rb
|
94
|
+
- lib/snipcheat/snippet.rb
|
95
|
+
- lib/snipcheat/snippet_dir.rb
|
96
|
+
- lib/snipcheat/task.rb
|
97
|
+
- lib/snipcheat/version.rb
|
98
|
+
- lib/templates/simple.html.haml
|
99
|
+
- snipcheat.gemspec
|
100
|
+
- spec/fixtures/no.snippet
|
101
|
+
- spec/fixtures/sample.sublime-snippet
|
102
|
+
- spec/output_spec.rb
|
103
|
+
- spec/snippet_dir_spec.rb
|
104
|
+
- spec/snippet_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: https://github.com/tadast/snipcheat
|
107
|
+
licenses: []
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.8.23
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Sublime Text 2 snippet cheat-sheet generator
|
130
|
+
test_files:
|
131
|
+
- spec/fixtures/no.snippet
|
132
|
+
- spec/fixtures/sample.sublime-snippet
|
133
|
+
- spec/output_spec.rb
|
134
|
+
- spec/snippet_dir_spec.rb
|
135
|
+
- spec/snippet_spec.rb
|
136
|
+
- spec/spec_helper.rb
|