oreilly-snippets 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0665f1c4662d4210fee1977523b0d67aea964901
4
- data.tar.gz: d56b78197b8912cd40869a692ea9f38d00d4d0aa
3
+ metadata.gz: f885055861b8a6cc216b6a62a9c68e9bef24ff66
4
+ data.tar.gz: f1753cb37934c3f84d51c550c5f036e669e3dc66
5
5
  SHA512:
6
- metadata.gz: df67277eed2c5692cb4bb2c703d7c212b74c7a70d6b131a6cc248180aca591ee871f1d2a65b208ffb44671e09d45f28e415069b467f2cf0eed63ebe253bd8749
7
- data.tar.gz: 2968b5febfa65029c32eedec864cfda1b0d7e74f48512a597422f774ddf5fa7681f0b8ecaa6270c507ac654907ef06549605fd54f60dc144504e4ecc92b640d6
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 of python content, you might not want to keep the indentation
113
- level as it is in the file, but display the content "flattened" to the
114
- smallest indentation level.
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
@@ -1,5 +1,5 @@
1
1
  module Oreilly
2
2
  module Snippets
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -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
@@ -0,0 +1,6 @@
1
+
2
+ public class Factorial {
3
+ public static void main( String[] args ) {
4
+ // Do something
5
+ }
6
+ }
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.8
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-05-22 00:00:00.000000000 Z
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