examplify 0.1.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.
- checksums.yaml +7 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/examplify +39 -0
- data/lib/examplify.rb +59 -0
- data/spec/dummy/one.rb +1 -0
- data/spec/dummy/two.rb +1 -0
- data/spec/feature_spec.rb +52 -0
- data/spec/spec_helper.rb +40 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0c192c87b698ab4fd1c0ddd819272c2e78ac35b
|
4
|
+
data.tar.gz: 770ffad0a0fbf87282e0895b50e3087f9ed6887e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fee3edb8b37706d68f3d9337d63c0f1df3a9626ccc10d53ce17017ee7c8d158b5088820e6247df51a6f00af88519d2702849fda943088496a3d01db5910bb322
|
7
|
+
data.tar.gz: 80dce84954c39e403924d71b03e14d4ac6bd2b825f7eda40a3f750ee618de26dcb529b4c435ada40c53d88bd3a9f836af608c898c3a4140591b8165ed7c7039d
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Examplify
|
2
|
+
|
3
|
+
Examplify squashes multiple files together into one for easily pasting into a
|
4
|
+
gist or a markdown document. It puts comments/headers with the filenames.
|
5
|
+
|
6
|
+
## Example output
|
7
|
+
|
8
|
+
```
|
9
|
+
# root/file.rb
|
10
|
+
contents of file.rb
|
11
|
+
|
12
|
+
# root/another_file.rb
|
13
|
+
contents of another_file.rb
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
```bash
|
19
|
+
# entire folder
|
20
|
+
examplify project/
|
21
|
+
|
22
|
+
# only ruby files
|
23
|
+
examplify project/ --only=*.rb
|
24
|
+
|
25
|
+
# without some files
|
26
|
+
examplify project/ --exclude=*.md
|
27
|
+
|
28
|
+
# choose specific files
|
29
|
+
examplify file.rb file2.rb
|
30
|
+
```
|
31
|
+
|
32
|
+
## Caveats
|
33
|
+
|
34
|
+
- globbing only matches on filenames for now
|
35
|
+
- zsh users probably want to `noglob examplify`, otherwise the shell will try to glob
|
36
|
+
- **very** weird behaviour can occur when dogfeeding this gem and not exluding the `.gem` files.
|
data/Rakefile
ADDED
data/bin/examplify
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "docopt"
|
4
|
+
require_relative '../lib/examplify.rb'
|
5
|
+
|
6
|
+
doc = <<DOCOPT
|
7
|
+
Examplify
|
8
|
+
|
9
|
+
Usage:
|
10
|
+
examplify <paths>... [--exclude=glob|--only=glob] [--dry-run]
|
11
|
+
examplify -h | --help
|
12
|
+
examplify --version
|
13
|
+
|
14
|
+
Options:
|
15
|
+
-h --help Show this screen.
|
16
|
+
--version Show version.
|
17
|
+
-n --dry-run Only output paths.
|
18
|
+
--exclude=glob Glob pattern of files to exclude.
|
19
|
+
--only=glob Glob pattern to filter files.
|
20
|
+
|
21
|
+
DOCOPT
|
22
|
+
|
23
|
+
begin
|
24
|
+
options = Docopt::docopt(doc)
|
25
|
+
|
26
|
+
list = Examplify.new(options["<paths>"])
|
27
|
+
|
28
|
+
list.filter(options["--only"]) if options["--only"]
|
29
|
+
list.exclude(options["--exclude"]) if options["--exclude"]
|
30
|
+
|
31
|
+
if options['--dry-run']
|
32
|
+
puts list.files
|
33
|
+
else
|
34
|
+
puts list.output
|
35
|
+
end
|
36
|
+
|
37
|
+
rescue Docopt::Exit => e
|
38
|
+
puts e.message
|
39
|
+
end
|
data/lib/examplify.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rake/file_list'
|
2
|
+
|
3
|
+
class Examplify
|
4
|
+
attr_reader :files
|
5
|
+
|
6
|
+
def initialize(paths)
|
7
|
+
@files = Rake::FileList[get_list_of_files(paths)]
|
8
|
+
end
|
9
|
+
|
10
|
+
def exclude(glob)
|
11
|
+
files.exclude do |path|
|
12
|
+
glob_matches_file(glob, path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# inverse of exclude
|
17
|
+
def filter(glob)
|
18
|
+
files.exclude do |path|
|
19
|
+
!glob_matches_file(glob, path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def output
|
24
|
+
files.map { |path|
|
25
|
+
title = ["# ", path].join
|
26
|
+
content = File.read(path)
|
27
|
+
|
28
|
+
[title, content].join("\n")
|
29
|
+
}.join("\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def glob_matches_file(glob, path)
|
35
|
+
filename = path.pathmap("%f")
|
36
|
+
File.fnmatch(glob, filename, File::FNM_DOTMATCH)
|
37
|
+
end
|
38
|
+
|
39
|
+
# given a path or a list of paths to folders or files
|
40
|
+
# returns an array of paths to all files given, and
|
41
|
+
# all files contained in subdirectories of folders,
|
42
|
+
# but without the folders
|
43
|
+
def get_list_of_files(paths)
|
44
|
+
paths = Array(paths)
|
45
|
+
|
46
|
+
paths.flat_map do |path|
|
47
|
+
if File.directory? path
|
48
|
+
get_all_files_inside(path)
|
49
|
+
else
|
50
|
+
[path]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_all_files_inside(folder)
|
56
|
+
# get paths of files recursively, ignoring paths to folders
|
57
|
+
Dir.glob(File.join(folder, '**/*')).reject { |path| File.directory? path }
|
58
|
+
end
|
59
|
+
end
|
data/spec/dummy/one.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
puts "One"
|
data/spec/dummy/two.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
puts "Two"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
describe "examplify" do
|
2
|
+
|
3
|
+
# TODO: Tempdir
|
4
|
+
|
5
|
+
it "outputs files from a folder" do
|
6
|
+
expect(examplify "./spec/dummy").to eq <<-OUTPUT.deindent
|
7
|
+
# ./spec/dummy/one.rb
|
8
|
+
puts "One"
|
9
|
+
|
10
|
+
# ./spec/dummy/two.rb
|
11
|
+
puts "Two"
|
12
|
+
OUTPUT
|
13
|
+
end
|
14
|
+
|
15
|
+
it "joins paths correctly" do
|
16
|
+
expect(examplify "./spec/dummy").to eq examplify "./spec/dummy/"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "ouputs manually listed files" do
|
20
|
+
expect(examplify "./spec/dummy/two.rb ./spec/dummy/one.rb").to eq <<-OUTPUT.deindent
|
21
|
+
# ./spec/dummy/two.rb
|
22
|
+
puts "Two"
|
23
|
+
|
24
|
+
# ./spec/dummy/one.rb
|
25
|
+
puts "One"
|
26
|
+
OUTPUT
|
27
|
+
end
|
28
|
+
|
29
|
+
it "excludes files by globbing" do
|
30
|
+
expect(examplify "./spec/dummy --exclude=*o.rb").to eq <<-OUTPUT.deindent
|
31
|
+
# ./spec/dummy/one.rb
|
32
|
+
puts "One"
|
33
|
+
OUTPUT
|
34
|
+
end
|
35
|
+
|
36
|
+
it "filters files by globbing" do
|
37
|
+
expect(examplify "./spec/dummy --only=two*").to eq <<-OUTPUT.deindent
|
38
|
+
# ./spec/dummy/two.rb
|
39
|
+
puts "Two"
|
40
|
+
OUTPUT
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can do a dry-run" do
|
44
|
+
expect(examplify "./spec/dummy -n").to eq <<-OUTPUT.deindent
|
45
|
+
./spec/dummy/one.rb
|
46
|
+
./spec/dummy/two.rb
|
47
|
+
OUTPUT
|
48
|
+
end
|
49
|
+
|
50
|
+
# it "file-prefix, line-prefix"
|
51
|
+
# it "git ls-files"
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
def examplify(arguments)
|
2
|
+
`ruby ./bin/examplify #{arguments}`
|
3
|
+
end
|
4
|
+
|
5
|
+
class String
|
6
|
+
def deindent
|
7
|
+
self.gsub(/ {6}/, '')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.expect_with :rspec do |expectations|
|
13
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
14
|
+
end
|
15
|
+
|
16
|
+
config.mock_with :rspec do |mocks|
|
17
|
+
mocks.verify_partial_doubles = true
|
18
|
+
end
|
19
|
+
|
20
|
+
config.filter_run :focus
|
21
|
+
config.run_all_when_everything_filtered = true
|
22
|
+
|
23
|
+
config.warnings = true
|
24
|
+
|
25
|
+
if config.files_to_run.one?
|
26
|
+
config.default_formatter = 'doc'
|
27
|
+
end
|
28
|
+
|
29
|
+
# Run specs in random order to surface order dependencies. If you find an
|
30
|
+
# order dependency and want to debug it, you can fix the order by providing
|
31
|
+
# the seed, which is printed after each run.
|
32
|
+
# --seed 1234
|
33
|
+
# config.order = :random
|
34
|
+
|
35
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
36
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
37
|
+
# test failures related to randomization by passing the same `--seed` value
|
38
|
+
# as the one that triggered the failure.
|
39
|
+
Kernel.srand config.seed
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: examplify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jimmy Börjesson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
description: Good for pasting an example that's using multiple files into a gist or
|
56
|
+
a blogpost.
|
57
|
+
email:
|
58
|
+
- lagginglion@gmail.com
|
59
|
+
executables:
|
60
|
+
- examplify
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- bin/examplify
|
67
|
+
- lib/examplify.rb
|
68
|
+
- spec/dummy/one.rb
|
69
|
+
- spec/dummy/two.rb
|
70
|
+
- spec/feature_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: https://github.com/alcesleo/examplify
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Outputs an entire project with filenames as comments.
|
96
|
+
test_files:
|
97
|
+
- spec/dummy/one.rb
|
98
|
+
- spec/dummy/two.rb
|
99
|
+
- spec/feature_spec.rb
|
100
|
+
- spec/spec_helper.rb
|