oreilly-snippets 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/oreilly/snippets/version.rb +1 -1
- data/lib/oreilly/snippets.rb +5 -1
- data/spec/fixtures/factorial.java +6 -0
- data/spec/process_spec.rb +19 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f885055861b8a6cc216b6a62a9c68e9bef24ff66
|
4
|
+
data.tar.gz: f1753cb37934c3f84d51c550c5f036e669e3dc66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7902c79fb4e7043f2e7ab4fa0820a1adf5e2b17ceac17d5b9767873abff5e7c2c25ea8aebff7db4290e1050df00c693d42439f07ff0d738fd74a1dc450458af
|
7
|
+
data.tar.gz: 7a27f369b5b3fc2f6073c0972aabfe3a2eaacf9b2366af47d8c3eb5d74e74639811c2e7b8dd9578352f6ebb518ca8db3fbe0cbe9a907ee23dee62e545491f24e
|
data/README.md
CHANGED
@@ -108,10 +108,10 @@ This will get replaced with `PLACEHOLDER TEXT, UPDATE WITH CORRECT SHA HASH`.
|
|
108
108
|
#### Flattening Identation
|
109
109
|
|
110
110
|
You can specify `flatten=true` and oreilly-snippets will flatten out
|
111
|
-
indentation. For example, if you are including a snippet python
|
112
|
-
content
|
113
|
-
|
114
|
-
|
111
|
+
indentation. For example, if you are including a snippet of python
|
112
|
+
content, you might not want to keep the indentation level as it is in
|
113
|
+
the file, but display the content "flattened" to the smallest
|
114
|
+
indentation level.
|
115
115
|
|
116
116
|
For example, imagine this content:
|
117
117
|
|
@@ -144,6 +144,8 @@ if anotherVar == "anotherVar"
|
|
144
144
|
If you want the default to be to flatten (avoiding setting it each
|
145
145
|
snippet declaration), you can set that using the config method: `Oreilly::Snippets.config( flatten: true )`
|
146
146
|
|
147
|
+
At the moment, flattening does not work perfectly for Java files. You can ignore java with `Oreilly::Snippets.config( flatten: true, flatten_exceptions: { java: true } )`
|
148
|
+
|
147
149
|
#### Incompatibilities with Atlas from O'Reilly
|
148
150
|
|
149
151
|
NB: This format of snippets is not currently compatible with Atlas
|
data/lib/oreilly/snippets.rb
CHANGED
@@ -55,7 +55,7 @@ module Oreilly
|
|
55
55
|
rv = contents
|
56
56
|
end
|
57
57
|
|
58
|
-
if flatten or @@_config[:flatten]
|
58
|
+
if ( flatten or @@_config[:flatten] ) and not flatten_exceptions( language )
|
59
59
|
rv = flatten_it( rv )
|
60
60
|
end
|
61
61
|
|
@@ -64,6 +64,10 @@ module Oreilly
|
|
64
64
|
rv
|
65
65
|
end
|
66
66
|
|
67
|
+
def self.flatten_exceptions( language )
|
68
|
+
@@_config[:flatten_exceptions] and @@_config[:flatten_exceptions][language.to_sym]
|
69
|
+
end
|
70
|
+
|
67
71
|
def self.flatten_it( content )
|
68
72
|
# find the smallest indent level, and then strip that off the beginning of all lines
|
69
73
|
smallest = nil
|
data/spec/process_spec.rb
CHANGED
@@ -54,6 +54,14 @@ specified code snippet when you build ebook outputs
|
|
54
54
|
snippet~~~~
|
55
55
|
END
|
56
56
|
|
57
|
+
DONT_USE_JAVA_FOR_FLATTENING = <<END
|
58
|
+
[filename="spec/fixtures/factorial.java", language="java", lines="3..5"]
|
59
|
+
snippet~~~~
|
60
|
+
Put any descriptive text you want here. It will be replaced with the
|
61
|
+
specified code snippet when you build ebook outputs
|
62
|
+
snippet~~~~
|
63
|
+
END
|
64
|
+
|
57
65
|
TEMPLATE = <<END
|
58
66
|
|
59
67
|
ABC
|
@@ -202,6 +210,17 @@ describe Oreilly::Snippets do
|
|
202
210
|
lines[-1][0].should match /\s/ # Last line is not indented
|
203
211
|
end
|
204
212
|
|
213
|
+
it "should not flatten if java is used and properly configured" do
|
214
|
+
string = <<END
|
215
|
+
public static void main( String[] args ) {
|
216
|
+
// Do something
|
217
|
+
}
|
218
|
+
END
|
219
|
+
Oreilly::Snippets.config( flatten: true, flatten_exceptions: { java: true } )
|
220
|
+
output = Oreilly::Snippets.process( DONT_USE_JAVA_FOR_FLATTENING )
|
221
|
+
string.should eq( output )
|
222
|
+
end
|
223
|
+
|
205
224
|
it "should support flattening with tabs" do
|
206
225
|
output = Oreilly::Snippets.process( FLATTEN_WITH_TABS )
|
207
226
|
output.should == @tabs_flattened
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oreilly-snippets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Dawson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/oreilly/snippets/version.rb
|
71
71
|
- oreilly-snippets.gemspec
|
72
72
|
- spec/fixtures/coffeetech.js
|
73
|
+
- spec/fixtures/factorial.java
|
73
74
|
- spec/fixtures/factorial.js
|
74
75
|
- spec/fixtures/with_spaces.rb
|
75
76
|
- spec/fixtures/with_tabs.rb
|
@@ -101,6 +102,7 @@ specification_version: 4
|
|
101
102
|
summary: See the README
|
102
103
|
test_files:
|
103
104
|
- spec/fixtures/coffeetech.js
|
105
|
+
- spec/fixtures/factorial.java
|
104
106
|
- spec/fixtures/factorial.js
|
105
107
|
- spec/fixtures/with_spaces.rb
|
106
108
|
- spec/fixtures/with_tabs.rb
|