rails-audio_glue 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46ff6190f4a333acbf050210d81979c661b03565
4
+ data.tar.gz: 89092439964b81c63dfeaab121484cf6819d6727
5
+ SHA512:
6
+ metadata.gz: 8fa6393352e06977ff0e3d88f3e7f5cd617588fd0cf9f7bd4e16731a4c04e945bba46fad21a7dbc29aa0dc490622ff26bfd3d4862545cfaf521d6933e903ad40
7
+ data.tar.gz: c09b95ef746dada28417636201bd6bef7cb135a38ce6e236a2fbcba21596fc46c5a1f8531b1ce750c4d8d12afe4334d8b876610797726de808971e640dc5b30b
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 TMX Credit, author Potapov Sergey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,122 @@
1
+ # Rails AudioGlue
2
+ [![Build Status](https://travis-ci.org/TMXCredit/rails-audio_glue.png)](https://travis-ci.org/TMXCredit/rails-audio_glue)
3
+
4
+ A Rails plugin which integrates AudioGlue - a library used to assemble audio
5
+ from snippets using templates.
6
+
7
+ ## Usage
8
+
9
+ ### Install
10
+
11
+ After adding `gem 'rails-audio_glue'` to `Gemfile` and running `bundle`,
12
+ run the generator to install the basic stuff:
13
+
14
+ ```sh
15
+ rails g rails_audio_glue:install
16
+
17
+ create config/initializers/audio_glue.rb
18
+ create app/audio_templates/audio_glue_helper.rb
19
+ ```
20
+
21
+ ### Audio templates
22
+
23
+ Now generate your first audio template:
24
+
25
+ ```sh
26
+ rails g rails_audio_glue:template hello_world
27
+
28
+ create app/audio_templates/hello_world.glue
29
+ ```
30
+
31
+ To get more info about `.glue` templates read
32
+ [AudioGlue's README](https://github.com/TMXCredit/audio_glue/).
33
+
34
+ Ensure you have the following `hello_world.glue` in `app/audio_templates`:
35
+
36
+ ```ruby
37
+ head {
38
+ format :mp3
39
+ rate 44100
40
+ channels 1
41
+ }
42
+
43
+ body {
44
+ - file("/path/to/audio/hello.wav")
45
+ if @say_bye
46
+ - url("http://some-server.com/say/bye.mp3")
47
+ end
48
+ }
49
+ ```
50
+
51
+ The output file parameters are described in the `head` section. And
52
+ the content is described in the `body` section. It's all pure ruby code.
53
+
54
+ ### Sending audio from controller
55
+
56
+ To build an audio file using a template and send it to a user, use the
57
+ `send_glued_audio` controller method. It receives a template name and template
58
+ variables as arguments and is built upon the `send_data` method:
59
+
60
+ ```ruby
61
+ class HelloController < ApplicationController
62
+ # Convert hello.wav to mp3 and send it as hello_world.mp3:
63
+ def hi
64
+ send_glued_audio('hello_world', :say_bye => false)
65
+ end
66
+
67
+ # Concatenate hello.wav and bye.mp3, convert to mp3, and send
68
+ # as hello_world.mp3:
69
+ def hi_and_bye
70
+ send_glued_audio('hello_world', :say_bye => true)
71
+ end
72
+ end
73
+ ```
74
+
75
+ ### Using helpers
76
+
77
+ To extend the `body` template section with custom methods, you need
78
+ to define them in `AudioGlueHelper`. Usually, they are supposed to based
79
+ upon the `file` and `url` methods.
80
+
81
+ ```ruby
82
+ module AudioGlueHelper
83
+ # The some-speaking-service is supposed to return audio file:
84
+ def say(text)
85
+ url("http://some-speaking-service.com/say/#{text}")
86
+ end
87
+ end
88
+ ```
89
+
90
+ Now you can use the `say` method in the `body` template section:
91
+
92
+ ```ruby
93
+ body {
94
+ - file("/path/to/audio/hello.wav")
95
+ - say("What's up?")
96
+ }
97
+ ```
98
+
99
+
100
+ ## Testing
101
+
102
+ ### Requirements
103
+
104
+ You must have the `sqlite3` package installed.
105
+
106
+ ### Running the Tests
107
+
108
+ ```sh
109
+ bundle
110
+ cd spec/dummy
111
+ rake db:setup db:migrate
112
+ cd -
113
+ rake spec
114
+ ```
115
+
116
+ ## Credits
117
+
118
+ * [Sergey Potapov](https://github.com/greyblake)
119
+
120
+ ## Copyright
121
+
122
+ Copyright (c) 2013 TMX Credit.
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Create initial files for AudioGlue engine.
3
+
4
+ Example:
5
+ rails generate rails_audio_glue:install
6
+
7
+ This will:
8
+ Create initializer: config/initializers/audio_glue.rb
9
+ Create helper: app/audio_templates/audio_glue_helper.rb
@@ -0,0 +1,21 @@
1
+ module RailsAudioGlue
2
+ # :nodoc:
3
+ module Generators
4
+ # :nodoc:
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ # :nodoc:
9
+ def create_initializer_file
10
+ template 'initializer.rb.erb', 'config/initializers/audio_glue.rb'
11
+ end
12
+
13
+ # :nodoc:
14
+ def create_audio_glue_helper
15
+ template 'audio_glue_helper.rb.erb',
16
+ "#{RailsAudioGlue::TEMPLATES_PATH}/audio_glue_helper.rb"
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ # A helper providing methods that can be executed in the +body+ section
2
+ # of +.glue+ templates.
3
+ # Methods are supposed to be based upon the +file+ and +url+ methods.
4
+ module AudioGlueHelper
5
+
6
+ end
@@ -0,0 +1,21 @@
1
+ RailsAudioGlue.setup do |config|
2
+ begin
3
+ require 'audio_glue/sox_adapter'
4
+ rescue LoadError
5
+ abort "You need to add `gem \"audio_glue-sox_adapter\"'" \
6
+ "to your Gemfile to use AudioGlue::SoxAdapter"
7
+ end
8
+
9
+
10
+ # Create AudioGlue adapter and builder:
11
+ adapter = ::AudioGlue::SoxAdapter.new
12
+ config.builder = ::AudioGlue::Builder.new(adapter)
13
+
14
+ # Create template loader
15
+ templates_path = Rails.application.root.
16
+ join(RailsAudioGlue::TEMPLATES_PATH).to_s
17
+ config.loader = ::AudioGlue::TemplateLoader.new(
18
+ templates_path,
19
+ :helper => AudioGlueHelper
20
+ )
21
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Create audio glue template
3
+
4
+ Example:
5
+ rails generate rails_audio_glue:template hello_world
6
+
7
+ This will:
8
+ Create template: app/audio_templates/hello_world.glue
@@ -0,0 +1,18 @@
1
+ module RailsAudioGlue
2
+ # :nodoc:
3
+ module Generators
4
+ # :nodoc:
5
+ class TemplateGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ argument :template_name, :type => :string
9
+
10
+ # :nodoc:
11
+ def create_template
12
+ template 'template.glue.erb',
13
+ "#{RailsAudioGlue::TEMPLATES_PATH}/#{template_name}.glue"
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ head {
2
+ format :mp3
3
+ rate 44100
4
+ channels 1
5
+ }
6
+
7
+ body {
8
+ - file('/path/to/file.wav')
9
+ - url('http://server.com/audio.mp3')
10
+ }
@@ -0,0 +1 @@
1
+ require File.expand_path('../rails_audio_glue', __FILE__)
@@ -0,0 +1,21 @@
1
+ require 'audio_glue'
2
+
3
+ require 'rails_audio_glue/controller_methods'
4
+ require 'rails_audio_glue/engine'
5
+
6
+ # Rails plugin which integrates the AudioGlue library.
7
+ module RailsAudioGlue
8
+ # The path to the directory where audio templates are supposed to be located.
9
+ TEMPLATES_PATH = 'app/audio_templates'
10
+
11
+ # Instance of AuduoGlue::Builder:
12
+ mattr_accessor :builder
13
+
14
+ # Instance of AuduoGlue::TemplateLoader:
15
+ mattr_accessor :loader
16
+
17
+ # Should be called from initializer to configure RailsAudioGlue.
18
+ def self.setup
19
+ yield self
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ module RailsAudioGlue
2
+ # Provides the +send_glued_audio+ method for ApplicationController.
3
+ module ControllerMethods
4
+ # Mapper for audio formats and mime types. If the format is unknown,
5
+ # it will generate it dynamically using a proc.
6
+ GLUE_MIME_TYPES = {
7
+ :mp3 => 'audio/mpeg',
8
+ :m4a => 'audio/mp4',
9
+ :ogg => 'audio/ogg',
10
+ :oga => 'audio/ogg',
11
+ :webma => 'audio/webm',
12
+ :wav => 'audio/wav',
13
+ }
14
+ GLUE_MIME_TYPES.default_proc = lambda { |hash, key| "audio/#{key}"}
15
+
16
+ # Assemble the audio using the passed template and variables.
17
+ # And send it as data.
18
+ #
19
+ # @param template_name [String] name of template in app/audio_templates
20
+ # @param variables [Hash] instance variables to initiate template.
21
+ #
22
+ # @return [void]
23
+ def send_glued_audio(template_name, variables = {})
24
+ loader = RailsAudioGlue.loader
25
+ builder = RailsAudioGlue.builder
26
+
27
+ # Reset the cache in development so we don't need to restart the server
28
+ # to see changes in the glue template.
29
+ loader.reset_cache! if Rails.env.development?
30
+
31
+ template = loader.get(template_name).new(variables)
32
+ data = builder.build(template)
33
+
34
+ format = template.format
35
+ filename = "#{File.basename(template_name)}.#{format}"
36
+ mime_type = GLUE_MIME_TYPES[format]
37
+
38
+ send_data(data, :filename => filename, :type => mime_type)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ module RailsAudioGlue
2
+ # :nodoc:
3
+ class Engine < ::Rails::Engine
4
+ initializer 'audio_glue' do
5
+
6
+ ::ActionController::Base.class_eval do
7
+ include RailsAudioGlue::ControllerMethods
8
+ end
9
+
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-audio_glue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TMX Credit
8
+ - Potapov Sergey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: audio_glue
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>'
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>'
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: jeweler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.7
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.7
70
+ - !ruby/object:Gem::Dependency
71
+ name: yard
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: sqlite3
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: pry
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: audio_glue-sox_adapter
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ~>
131
+ - !ruby/object:Gem::Version
132
+ version: 0.0.1
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: 0.0.1
140
+ - !ruby/object:Gem::Dependency
141
+ name: metric_fu
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: Rails-AudioGlue is an audio template engine (aka ERB/HAML for sounds)
155
+ email:
156
+ - rubygems@tmxcredit.com
157
+ - blake131313@gmail.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files:
161
+ - LICENSE.txt
162
+ - README.markdown
163
+ files:
164
+ - LICENSE.txt
165
+ - README.markdown
166
+ - lib/generators/rails_audio_glue/install/USAGE
167
+ - lib/generators/rails_audio_glue/install/install_generator.rb
168
+ - lib/generators/rails_audio_glue/install/templates/audio_glue_helper.rb.erb
169
+ - lib/generators/rails_audio_glue/install/templates/initializer.rb.erb
170
+ - lib/generators/rails_audio_glue/template/USAGE
171
+ - lib/generators/rails_audio_glue/template/template_generator.rb
172
+ - lib/generators/rails_audio_glue/template/templates/template.glue.erb
173
+ - lib/rails-audio_glue.rb
174
+ - lib/rails_audio_glue.rb
175
+ - lib/rails_audio_glue/controller_methods.rb
176
+ - lib/rails_audio_glue/engine.rb
177
+ homepage: http://github.com/TMXCredit/rails-audio_glue
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.0.3
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: AudioGlue plugin for Rails
201
+ test_files: []
202
+ has_rdoc: