trundle 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f26381e6daf38ba9ec6a3e756ce71e4cffba2fc
4
- data.tar.gz: f9a7f0c9858604929a667f6f1cd13e3f5be21542
3
+ metadata.gz: cff10562e374c8a068234010a6fc43ca8ec3cf03
4
+ data.tar.gz: 5884e8f3a049f90896d049718ca093f74cdb2e08
5
5
  SHA512:
6
- metadata.gz: 2db5e7d5058d0b4e380afe0d9931b1d067ee56c145349c5c4246dc82acf2e575bfceea6103ab1fe8e7a7faddeb5ac4c10e756c7fcdbbd3816f281a0211eb164b
7
- data.tar.gz: 34973269859c359dd0a4ead77bda5b940f19a264e1d3827b6b9ace03906ad1cbeae87e3a0c471e0ab5b39994f86a89118b2cfaa6ed18090d8e39d76a249d16e0
6
+ metadata.gz: fde5196831aa956477bae27119c0ff4cb30959e3a56d0bff0eff25a2dac589eb89ec3b5146e7d58293b15f94e29cfb8a8a9bf85eaeaf58a20bfdb90d529d7399
7
+ data.tar.gz: 25d00dabec98c7c957c239f87fe2b4527ac2d9fe9f189f4a8559bd01b8b9ef118b588d1b9afaa66a01b66fbf5bed513c96970e83a492ffd1a10bc034ed198ee1
data/lib/trundle.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'trundle/version'
2
2
  require 'trundle/info_accessors'
3
3
 
4
+ require 'trundle/asset_store'
4
5
  require 'trundle/config'
5
6
  require 'trundle/info_store'
6
7
  require 'trundle/key'
@@ -9,16 +10,13 @@ require 'trundle/namespaced_attributes'
9
10
  require 'trundle/text_bundle'
10
11
  require 'trundle/text_store'
11
12
 
12
- class Trundle
13
+ module Trundle
13
14
 
14
15
  class NamespaceNotDefined < StandardError; end
15
16
 
16
17
  def self.open(path)
17
- if block_given?
18
- TextBundle.new(path, &Proc.new)
19
- else
20
- TextBundle.new(path)
21
- end
18
+ return TextBundle.new(path, &Proc.new) if block_given?
19
+ TextBundle.new(path)
22
20
  end
23
21
 
24
22
  def self.configure
@@ -0,0 +1,28 @@
1
+ class Trundle::AssetStore
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+
6
+ def [](file_path)
7
+ assets[normalise_file_path(file_path)]
8
+ end
9
+
10
+ def length
11
+ assets.length
12
+ end
13
+
14
+ private
15
+ attr_accessor :path
16
+
17
+ def assets
18
+ @assets ||= Dir.glob(File.join(path, '**/*.*')).collect do |file_path|
19
+ [normalise_file_path(file_path), Pathname.new(file_path)]
20
+ end.to_h
21
+ end
22
+
23
+ def normalise_file_path(file_path)
24
+ file_path = file_path.gsub(path, '')
25
+ file_path = file_path.gsub(/^(\.|\/)/, '')
26
+ file_path
27
+ end
28
+ end
@@ -22,11 +22,8 @@ class Trundle::Config
22
22
  end
23
23
 
24
24
  def namespaces(&block)
25
- if block_given?
26
- namespace_list.instance_eval(&block)
27
- else
28
- namespace_list.all
29
- end
25
+ return namespace_list.instance_eval(&block) if block_given?
26
+ namespace_list.all
30
27
  end
31
28
 
32
29
  def transient=(value)
@@ -1,6 +1,7 @@
1
1
  class Trundle::TextBundle
2
2
  extend Trundle::InfoAccessors
3
3
 
4
+ attr_reader :path
4
5
  info_accessors(
5
6
  :creator_identifier,
6
7
  :creator_url,
@@ -14,6 +15,7 @@ class Trundle::TextBundle
14
15
  @path = path
15
16
  @info_store = Trundle::InfoStore.new(File.join(@path, 'info.json'))
16
17
  @text_store = Trundle::TextStore.new(File.join(@path, 'text.markdown'))
18
+ @asset_store = Trundle::AssetStore.new(File.join(@path, 'assets'))
17
19
 
18
20
  @info_store.content = Trundle.config.to_h unless exist?
19
21
 
@@ -35,6 +37,10 @@ class Trundle::TextBundle
35
37
  @text_store.content = value
36
38
  end
37
39
 
40
+ def assets
41
+ @asset_store
42
+ end
43
+
38
44
  def close
39
45
  Dir.mkdir(@path) unless exist?
40
46
  write_namespaces
@@ -1,3 +1,3 @@
1
- class Trundle
2
- VERSION = '0.1.0'
1
+ module Trundle
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,31 @@
1
+ RSpec.describe Trundle::TextBundle do
2
+ describe 'Assets' do
3
+ let(:file) { Pathname.new(file_path) }
4
+ let(:file_path) { text_bundle_path + '/assets/' + file_name }
5
+ let(:text_bundle) { described_class.new(text_bundle_path) }
6
+
7
+ describe 'Reading' do
8
+ let(:text_bundle_path) { 'spec/samples/assets.textbundle' }
9
+
10
+ it 'has three assets' do
11
+ expect(text_bundle.assets.length).to eq(3)
12
+ end
13
+
14
+ context 'file in the assets folder' do
15
+ let(:file_name) { 'colours.txt' }
16
+
17
+ it 'can be accessed' do
18
+ expect(text_bundle.assets[file_name]).to eq(file)
19
+ end
20
+ end
21
+
22
+ context 'file in a sub folder' do
23
+ let(:file_name) { 'images/red.jpg' }
24
+
25
+ it 'can be accessed' do
26
+ expect(text_bundle.assets[file_name]).to eq(file)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -8,6 +8,10 @@ RSpec.describe Trundle::TextBundle do
8
8
  expect(text_bundle).to exist
9
9
  end
10
10
 
11
+ it 'has a path' do
12
+ expect(text_bundle.path).to eq(text_bundle_path)
13
+ end
14
+
11
15
  context 'when configuration options are set' do
12
16
  let(:text_bundle_path) { 'spec/samples/blank.textbundle' }
13
17
 
@@ -0,0 +1,2 @@
1
+ Red
2
+ Yellow
@@ -0,0 +1 @@
1
+ {}
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Pearson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-12 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,6 +81,7 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/trundle.rb
84
+ - lib/trundle/asset_store.rb
84
85
  - lib/trundle/config.rb
85
86
  - lib/trundle/info_accessors.rb
86
87
  - lib/trundle/info_store.rb
@@ -93,11 +94,17 @@ files:
93
94
  - spec/lib/config_spec.rb
94
95
  - spec/lib/key_spec.rb
95
96
  - spec/lib/namespace_list_spec.rb
97
+ - spec/lib/text_bundle/assets_spec.rb
96
98
  - spec/lib/text_bundle/info_spec.rb
97
99
  - spec/lib/text_bundle/namespaces_spec.rb
98
100
  - spec/lib/text_bundle/text_spec.rb
99
101
  - spec/lib/text_bundle_spec.rb
100
102
  - spec/lib/trundle_spec.rb
103
+ - spec/samples/assets.textbundle/assets/colours.txt
104
+ - spec/samples/assets.textbundle/assets/images/red.jpg
105
+ - spec/samples/assets.textbundle/assets/images/yellow.jpg
106
+ - spec/samples/assets.textbundle/info.json
107
+ - spec/samples/assets.textbundle/text.markdown
101
108
  - spec/samples/blank.textbundle/info.json
102
109
  - spec/samples/blank.textbundle/text.markdown
103
110
  - spec/samples/namespaces.textbundle/info.json
@@ -136,11 +143,17 @@ test_files:
136
143
  - spec/lib/config_spec.rb
137
144
  - spec/lib/key_spec.rb
138
145
  - spec/lib/namespace_list_spec.rb
146
+ - spec/lib/text_bundle/assets_spec.rb
139
147
  - spec/lib/text_bundle/info_spec.rb
140
148
  - spec/lib/text_bundle/namespaces_spec.rb
141
149
  - spec/lib/text_bundle/text_spec.rb
142
150
  - spec/lib/text_bundle_spec.rb
143
151
  - spec/lib/trundle_spec.rb
152
+ - spec/samples/assets.textbundle/assets/colours.txt
153
+ - spec/samples/assets.textbundle/assets/images/red.jpg
154
+ - spec/samples/assets.textbundle/assets/images/yellow.jpg
155
+ - spec/samples/assets.textbundle/info.json
156
+ - spec/samples/assets.textbundle/text.markdown
144
157
  - spec/samples/blank.textbundle/info.json
145
158
  - spec/samples/blank.textbundle/text.markdown
146
159
  - spec/samples/namespaces.textbundle/info.json