volt 0.2.3 → 0.2.4
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 +4 -4
- data/Readme.md +3 -0
- data/VERSION +1 -1
- data/docs/GUIDE.md +3 -3
- data/lib/volt.rb +0 -2
- data/lib/volt/cli.rb +14 -1
- data/lib/volt/cli/new_gem.rb +116 -0
- data/lib/volt/controllers/model_controller.rb +4 -0
- data/lib/volt/router/routes.rb +10 -7
- data/lib/volt/server.rb +36 -96
- data/lib/volt/server/channel_handler.rb +1 -1
- data/lib/volt/server/rack/component_files.rb +97 -0
- data/lib/volt/server/rack/component_paths.rb +70 -0
- data/lib/volt/server/rack/index_files.rb +38 -0
- data/lib/volt/server/rack/opal_files.rb +51 -0
- data/lib/volt/server/{source_map_server.rb → rack/source_map_server.rb} +0 -0
- data/lib/volt/templates/page.rb +3 -5
- data/{templates/app/.empty_directory → spec/app/main/assets/js/test1.js} +0 -0
- data/spec/app/main/config/dependencies.rb +1 -0
- data/{templates/app/home/css/.empty_directory → spec/app/shared/assets/js/test2.js} +0 -0
- data/spec/app/shared/config/dependencies.rb +1 -0
- data/spec/server/rack/component_files_spec.rb +23 -0
- data/spec/server/rack/component_paths_spec.rb +26 -0
- data/spec/store/mongo_spec.rb +5 -2
- data/templates/newgem/Gemfile.tt +4 -0
- data/templates/newgem/LICENSE.txt.tt +22 -0
- data/templates/newgem/README.md.tt +29 -0
- data/templates/newgem/Rakefile.tt +16 -0
- data/templates/newgem/VERSION +1 -0
- data/templates/{app/home/models → newgem/app/newgem/assets/css}/.empty_directory +0 -0
- data/templates/{public/css/ansi.css → newgem/app/newgem/assets/js/.empty_directory} +0 -0
- data/templates/newgem/bin/newgem.tt +3 -0
- data/templates/newgem/gitignore.tt +17 -0
- data/templates/newgem/lib/newgem.rb.tt +9 -0
- data/templates/{public/js/bootstrap.js → newgem/lib/newgem/.empty_directory} +0 -0
- data/templates/newgem/newgem.gemspec.tt +28 -0
- data/templates/newgem/rspec.tt +2 -0
- data/templates/newgem/spec/newgem_spec.rb.tt +11 -0
- data/templates/newgem/spec/spec_helper.rb.tt +2 -0
- data/templates/newgem/test/minitest_helper.rb.tt +4 -0
- data/templates/newgem/test/test_newgem.rb.tt +11 -0
- data/templates/{Gemfile.tt → project/Gemfile.tt} +4 -1
- data/templates/project/app/.empty_directory +0 -0
- data/templates/{app → project/app}/home/config/routes.rb +0 -0
- data/templates/{app → project/app}/home/controllers/index_controller.rb +0 -0
- data/templates/project/app/home/css/.empty_directory +0 -0
- data/templates/project/app/home/models/.empty_directory +0 -0
- data/templates/{app → project/app}/home/views/index/about.html +0 -0
- data/templates/{app → project/app}/home/views/index/home.html +0 -0
- data/templates/{app → project/app}/home/views/index/index.html +0 -0
- data/templates/{config.ru → project/config.ru} +1 -1
- data/templates/project/public/css/ansi.css +0 -0
- data/templates/{public → project/public}/css/bootstrap-theme.css +0 -0
- data/templates/{public → project/public}/css/bootstrap.css +0 -0
- data/templates/{public → project/public}/css/jumbotron.css +0 -0
- data/templates/{public → project/public}/fonts/glyphicons-halflings-regular.eot +0 -0
- data/templates/{public → project/public}/fonts/glyphicons-halflings-regular.svg +0 -0
- data/templates/{public → project/public}/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/templates/{public → project/public}/fonts/glyphicons-halflings-regular.woff +0 -0
- data/templates/project/public/index.html +19 -0
- data/templates/project/public/js/bootstrap.js +0 -0
- data/templates/{public → project/public}/js/jquery-2.0.3.js +0 -0
- data/templates/{public → project/public}/js/sockjs-0.2.1.min.js +0 -0
- data/templates/{spec → project/spec}/spec_helper.rb +0 -0
- metadata +60 -27
- data/lib/volt/server/request_handler.rb +0 -16
- data/templates/public/index.html +0 -25
@@ -0,0 +1,70 @@
|
|
1
|
+
class ComponentPaths
|
2
|
+
def initialize(root=nil)
|
3
|
+
@root = root || Dir.pwd
|
4
|
+
end
|
5
|
+
|
6
|
+
# Yield for every folder where we might find components
|
7
|
+
def app_folders
|
8
|
+
# Find all app folders
|
9
|
+
@app_folders ||= begin
|
10
|
+
app_folders = ["#{@root}/app", "#{@root}/vendor/app"].map {|f| File.expand_path(f) }
|
11
|
+
|
12
|
+
# Gem folders with volt in them
|
13
|
+
# TODO: we should probably qualify this a bit more
|
14
|
+
app_folders += Gem.loaded_specs.values.map { |g| g.full_gem_path }.reject {|g| g !~ /volt/ }.map {|f| f + '/app' }
|
15
|
+
|
16
|
+
app_folders
|
17
|
+
end
|
18
|
+
|
19
|
+
# Yield each app folder and return a flattened array with
|
20
|
+
# the results
|
21
|
+
|
22
|
+
files = []
|
23
|
+
@app_folders.each do |app_folder|
|
24
|
+
files << yield(app_folder)
|
25
|
+
end
|
26
|
+
|
27
|
+
return files.flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def components
|
31
|
+
return @components if @components
|
32
|
+
|
33
|
+
@components = {}
|
34
|
+
app_folders do |app_folder|
|
35
|
+
Dir["#{app_folder}/*"].each do |folder|
|
36
|
+
if File.directory?(folder)
|
37
|
+
folder_name = folder[/[^\/]+$/]
|
38
|
+
|
39
|
+
@components[folder_name] ||= []
|
40
|
+
@components[folder_name] << folder
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
return @components
|
46
|
+
end
|
47
|
+
|
48
|
+
def component_path(name)
|
49
|
+
folders = components[name]
|
50
|
+
|
51
|
+
if folders
|
52
|
+
return folders.first
|
53
|
+
else
|
54
|
+
return nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return every asset folder we need to serve from
|
59
|
+
def asset_folders
|
60
|
+
folders = []
|
61
|
+
app_folders do |app_folder|
|
62
|
+
Dir["#{app_folder}/*/assets"].each do |asset_folder|
|
63
|
+
folders << yield(asset_folder)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
folders.flatten
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'volt/server/rack/component_files'
|
2
|
+
|
3
|
+
# Serves the main pages
|
4
|
+
class IndexFiles
|
5
|
+
def initialize(app, component_paths)
|
6
|
+
@app = app
|
7
|
+
@component_paths = component_paths
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
if %w[/ /demo /blog /todos /page3 /page4].include?(env['PATH_INFO']) || env['PATH_INFO'][0..5] == '/todos'
|
12
|
+
[200, { 'Content-Type' => 'text/html' }, [html]]
|
13
|
+
else
|
14
|
+
@app.call env
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def html
|
19
|
+
index_path = File.expand_path(File.join(Dir.pwd, "public/index.html"))
|
20
|
+
html = File.read(index_path)
|
21
|
+
|
22
|
+
ERB.new(html).result(binding)
|
23
|
+
end
|
24
|
+
|
25
|
+
def javascript_files
|
26
|
+
# TODO: OPTimize
|
27
|
+
ComponentFiles.new('home', @component_paths).javascript_files
|
28
|
+
end
|
29
|
+
|
30
|
+
def css_files
|
31
|
+
ComponentFiles.new('home', @component_paths).css_files
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'volt/server/rack/source_map_server'
|
2
|
+
|
3
|
+
SOURCE_MAPS = !!ENV['MAPS'] unless defined?(SOURCE_MAPS)
|
4
|
+
|
5
|
+
Opal::Processor.source_map_enabled = SOURCE_MAPS
|
6
|
+
# Opal::Processor.arity_check_enabled = true
|
7
|
+
# Opal::Processor.dynamic_require_severity = :raise
|
8
|
+
|
9
|
+
# Sets up the maps for the opal assets, and source maps if enabled.
|
10
|
+
class OpalFiles
|
11
|
+
def initialize(builder, app_path, component_paths)
|
12
|
+
@component_paths = component_paths
|
13
|
+
environment = Opal::Environment.new
|
14
|
+
environment.cache = Sprockets::Cache::FileStore.new("./tmp")
|
15
|
+
|
16
|
+
environment.append_path(app_path)
|
17
|
+
|
18
|
+
volt_gem_lib_path = File.expand_path(File.join(File.dirname(__FILE__), "../../.."))
|
19
|
+
environment.append_path(volt_gem_lib_path)
|
20
|
+
|
21
|
+
add_asset_folders(environment)
|
22
|
+
|
23
|
+
# Add the opal load paths
|
24
|
+
Opal.paths.each do |path|
|
25
|
+
environment.append_path(path)
|
26
|
+
end
|
27
|
+
|
28
|
+
# opal-jquery gem
|
29
|
+
spec = Gem::Specification.find_by_name("opal-jquery")
|
30
|
+
environment.append_path(spec.gem_dir + "/opal")
|
31
|
+
|
32
|
+
builder.map '/assets' do
|
33
|
+
run environment
|
34
|
+
end
|
35
|
+
|
36
|
+
if SOURCE_MAPS
|
37
|
+
source_maps = SourceMapServer.new(environment)
|
38
|
+
|
39
|
+
builder.map(source_maps.prefix) do
|
40
|
+
run source_maps
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_asset_folders(environment)
|
46
|
+
@component_paths.asset_folders do |asset_folder|
|
47
|
+
environment.append_path(asset_folder)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
File without changes
|
data/lib/volt/templates/page.rb
CHANGED
@@ -64,11 +64,9 @@ class Page
|
|
64
64
|
});
|
65
65
|
}
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# # `console.log('got: ', message);`
|
71
|
-
# end
|
67
|
+
channel.on('message') do |message|
|
68
|
+
puts "GOT: #{message}"
|
69
|
+
end
|
72
70
|
end
|
73
71
|
|
74
72
|
def link_clicked(url)
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
component 'shared'
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
component 'bootstrap'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'volt/server/rack/component_files'
|
2
|
+
|
3
|
+
describe ComponentFiles do
|
4
|
+
before do
|
5
|
+
spec_app_root = File.join(File.dirname(__FILE__), "../..")
|
6
|
+
|
7
|
+
path_to_main = File.join(File.dirname(__FILE__), "../../app/main")
|
8
|
+
@component_paths = ComponentPaths.new(spec_app_root)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return the dependencies list" do
|
12
|
+
main = ComponentFiles.new("main", @component_paths)
|
13
|
+
|
14
|
+
components = main.components
|
15
|
+
expect(components).to eq(['main', 'shared', 'bootstrap'])
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should list all JS files" do
|
19
|
+
main = ComponentFiles.new("main", @component_paths)
|
20
|
+
|
21
|
+
expect(main.javascript_files).to eq(["/assets/volt/templates/page.js", "/components/home.js", "/assets/js/test2.js", "/assets/js/test1.js"])
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'volt/server/rack/component_paths'
|
2
|
+
|
3
|
+
describe ComponentPaths do
|
4
|
+
before do
|
5
|
+
spec_app_root = File.join(File.dirname(__FILE__), "../..")
|
6
|
+
|
7
|
+
path_to_main = File.join(File.dirname(__FILE__), "../../app/main")
|
8
|
+
@component_paths = ComponentPaths.new(spec_app_root)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return the paths to all app folders" do
|
12
|
+
match_count = 0
|
13
|
+
@component_paths.app_folders do |app_folder|
|
14
|
+
if app_folder[/spec\/app$/] || app_folder[/spec\/vendor\/app$/]
|
15
|
+
match_count += 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(match_count).to eq(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return the path to a component" do
|
23
|
+
main_path = @component_paths.component_path('main')
|
24
|
+
expect(main_path).to match(/spec\/app\/main$/)
|
25
|
+
end
|
26
|
+
end
|
data/spec/store/mongo_spec.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) <%=Time.now.year%> <%=config[:author]%>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# <%=config[:constant_name]%>
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem '<%=config[:name]%>'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install <%=config[:name]%>
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/[my-github-username]/<%=config[:name]%>/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
<% if config[:test] == 'minitest' -%>
|
3
|
+
require "rake/testtask"
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
end
|
8
|
+
|
9
|
+
task :default => :test
|
10
|
+
<% elsif config[:test] == 'rspec' -%>
|
11
|
+
require "rspec/core/rake_task"
|
12
|
+
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
|
15
|
+
task :default => :spec
|
16
|
+
<% end -%>
|
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
File without changes
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "<%=config[:namespaced_path]%>/version"
|
2
|
+
|
3
|
+
<%- config[:constant_array].each_with_index do |c,i| -%>
|
4
|
+
<%= ' '*i %>class <%= c %>
|
5
|
+
<%- end -%>
|
6
|
+
<%= ' '*config[:constant_array].size %># Your code goes here...
|
7
|
+
<%- (config[:constant_array].size-1).downto(0) do |i| -%>
|
8
|
+
<%= ' '*i %>end
|
9
|
+
<%- end -%>
|
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
version = File.read(File.expand_path('../VERSION', __FILE__)).strip
|
6
|
+
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = <%=config[:name].inspect%>
|
10
|
+
spec.version = version
|
11
|
+
spec.authors = [<%=config[:author].inspect%>]
|
12
|
+
spec.email = [<%=config[:email].inspect%>]
|
13
|
+
spec.summary = %q{TODO: Write a short summary. Required.}
|
14
|
+
spec.description = %q{TODO: Write a longer description. Optional.}
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "volt", "~> <%= config[:volt_version_base] %>"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
<% if config[:test] -%>
|
26
|
+
spec.add_development_dependency "<%=config[:test]%>"
|
27
|
+
<% end -%>
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class Test<%= config[:constant_name] %> < MiniTest::Unit::TestCase
|
4
|
+
def test_that_it_has_a_version_number
|
5
|
+
refute_nil ::<%= config[:constant_name] %>::VERSION
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_it_does_something_useful
|
9
|
+
assert false
|
10
|
+
end
|
11
|
+
end
|