rubyhtmlapp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d0968fb97c66308e369dd5937c4c164a9e257ca
4
+ data.tar.gz: e3cba029038a9e9f78a34331efcc73436db18420
5
+ SHA512:
6
+ metadata.gz: 99f9cdc9c019d67c993cf65802ab9d75cc38e35e470e3764f10f2d177c004770412476625e4e13c230d4ecf2995c00efb5792b0dffec7bc8589e5f2ffc41abe6
7
+ data.tar.gz: e0df598eba603e52933bb8714d79b92ece2e12f5faa4dea44d1edfc4f00b692167f0b396298de25a13ad952cdc7f467027e668ee7420a8e07f5d2777fa942fcb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in RubyHtmlApp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Curtis Bissonnette
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # RubyHtmlApp
2
+
3
+ Creates an inlined html app using sprockets and tilt
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubyhtmlapp'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubyhtmlapp
18
+
19
+ ## Usage
20
+
21
+ To create a blank project run:
22
+ rubyhtmlapp create [project_name]
23
+
24
+ This will intitialize a git repository and setup a simple hello world example. To 'compile' the project run:
25
+ bundle exec ruby bin/[project_name] compile
26
+
27
+ This will inline all js files located in the lib/[project_name]/javascripts directory, all css files located in lib/[project_name]/stylesheets into the template application.html (using layout.html). The final result will be located in the dist/ directory.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubyhtmlapp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubyhtmlapp"
8
+ spec.version = RubyHtmlApp::VERSION
9
+ spec.authors = ["Curtis Bissonnette"]
10
+ spec.email = ["cbissonnette@gmail.com"]
11
+ spec.description = %q{Creates an inlined html app using sprockets and tilt}
12
+ spec.summary = %q{A simple generator used to setup a project for sprockets and tilt
13
+ which will compile all source files into a single html file}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "pry"
25
+
26
+ spec.add_dependency "tilt", "~> 1.3.6"
27
+ spec.add_dependency "sprockets", "~> 2.9.0"
28
+ spec.add_dependency "templater", "~> 1.0.0"
29
+ spec.add_dependency "thor", "~> 0.18.1"
30
+
31
+ end
data/bin/rubyhtmlapp ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubyhtmlapp'
4
+
5
+ RubyHtmlApp::CLI.start(ARGV)
@@ -0,0 +1,69 @@
1
+ #bundler
2
+ require 'bundler/setup'
3
+
4
+ #ruby internals
5
+ require 'find'
6
+
7
+ #external gems
8
+ require 'sprockets'
9
+ require 'tilt'
10
+ require 'thor'
11
+ require 'templater'
12
+
13
+ #gem files
14
+ require 'RubyHtmlApp/version'
15
+ require 'RubyHtmlApp/helpers'
16
+ require 'RubyHtmlApp/cli'
17
+
18
+ module RubyHtmlApp
19
+ class HtmlApp
20
+ include Helpers
21
+
22
+ def initialize(application_name, args={})
23
+ @app_name = application_name
24
+ @app_path = args.fetch(:app_path, File.join('lib', application_name))
25
+ @partial_path = File.join(@app_path, args.fetch(:partial_path, "html"))
26
+ @layout_path = File.join(@app_path, args.fetch(:layout_path, "html"))
27
+ @html_path = File.join(@app_path, args.fetch(:html_path, "html"))
28
+ @html_path = File.join(@app_path, args.fetch(:html_path, "html"))
29
+ @js_path = File.join(@app_path, args.fetch(:js_path, "javascripts"))
30
+ @css_path = File.join(@app_path, args.fetch(:css_path, "stylesheets"))
31
+ @image_path = File.join(@app_path, args.fetch(:image_path, "images"))
32
+ @js_compressor = args.fetch(:js_compressor, nil) #Uglifier.new
33
+ @css_compressor = args.fetch(:css_compressor, nil) #YUI::CssCompressor.new
34
+ @build_path = args.fetch(:build_path, 'dist')
35
+ @build_name = args.fetch(:build_name, @app_name)
36
+ @build_name.concat('.html') if File.extname(@build_name) == ''
37
+ @main_js = args.fetch(:app_js, "application.js")
38
+ @main_css = args.fetch(:app_css, "application.css")
39
+ @main_layout = args.fetch(:app_layout, "layout.html*")
40
+ @main_html = args.fetch(:app_html, "application.html*")
41
+ @sprocket_env = Sprockets::Environment.new
42
+ end
43
+
44
+ def compile_resources()
45
+ @sprocket_env.append_path @js_path
46
+ @sprocket_env.append_path @css_path
47
+ @sprocket_env.append_path @image_path
48
+ @sprocket_env.js_compressor = @js_compressor
49
+ @sprocket_env.css_compressor = @css_compressor
50
+
51
+ css_source = @sprocket_env[@main_css].source
52
+ js_source = @sprocket_env[@main_js].source
53
+
54
+ FileUtils.mkpath(@build_path) if !File.exists?(@build_path)
55
+ File.open(File.join(@build_path, @build_name), "w") do |f|
56
+ layout = find_f(@layout_path, @main_layout)
57
+ output = Tilt.new(find_f(@html_path, @main_html)).render(self,
58
+ inline_js: js_source,
59
+ inline_css: css_source)
60
+ if layout
61
+ output = Tilt.new(layout).render(self,
62
+ inline_js: js_source,
63
+ inline_css: css_source) { output }
64
+ end
65
+ f.write(output)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,57 @@
1
+ require 'templater'
2
+ require 'thor'
3
+
4
+ module RubyHtmlApp
5
+ class FileGenerator < Templater::Generator
6
+
7
+ def initialize(target, args)
8
+ @params = args
9
+ super(target)
10
+ end
11
+
12
+ def self.source_root
13
+ File.join(File.dirname(__FILE__), 'templates')
14
+ end
15
+ end
16
+
17
+ class CLI < Thor
18
+ desc "create", "create a new ruby html app"
19
+ def create(raw_name)
20
+ name = raw_name.chomp("/")
21
+ namespaced_path = name.tr('-', '/')
22
+ target = File.join(Dir.pwd, name)
23
+ constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
24
+ constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
25
+ constant_array = constant_name.split('::')
26
+ git_user_name = `git config user.name`.chomp
27
+ git_user_email = `git config user.email`.chomp
28
+ `bundle gem #{raw_name}`
29
+ opts = {
30
+ :name => name,
31
+ :namespaced_path => namespaced_path,
32
+ :constant_name => constant_name,
33
+ :constant_array => constant_array,
34
+ :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
35
+ :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
36
+ :test => options[:test]
37
+ }
38
+ gen = FileGenerator.new(name, opts)
39
+ #static files
40
+ FileGenerator.file(:application_html, "html/application.html.haml", "lib/#{name}/html/application.html.haml")
41
+ FileGenerator.file(:layout_html, "html/layout.html.haml", "lib/#{name}/html/layout.html.haml")
42
+ FileGenerator.empty_directory(:images, "lib/#{name}/images/")
43
+ FileGenerator.file(:application_js, "javascripts/application.js", "lib/#{name}/javascripts/application.js")
44
+ FileGenerator.file(:application_css, "stylesheets/application.css.scss", "lib/#{name}/stylesheets/application.css.scss")
45
+ FileGenerator.empty_directory(:dist, "dist/")
46
+
47
+ #erb files
48
+ FileGenerator.template(:cli, "cli.rb", "lib/#{name}/cli.rb")
49
+ FileGenerator.template(:run, "run", "bin/#{name}")
50
+ FileGenerator.template(:gemspec, "newgem.gemspec", "#{name}.gemspec")
51
+ FileGenerator.template(:app, "newgem.rb", "lib/#{name}.rb")
52
+ gen.invoke!
53
+ Dir.chdir(name) { `git add .`; `git commit -m "initialize rubyhtmlapp"`; }
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ require 'tilt'
2
+ require 'sprockets'
3
+ require 'find'
4
+
5
+ module RubyHtmlApp
6
+ module Helpers
7
+ def render(partial, locals={}, &block)
8
+ Tilt.new(find_f(@partial_path, "_#{partial}.html*"),
9
+ locals,
10
+ &block).render(self)
11
+ end
12
+
13
+ def asset_data_uri(path)
14
+ asset = @sprocket_env[path]
15
+ Sprockets::Context.new(@sprocket_env, asset.logical_path, asset.pathname).asset_data_uri(path)
16
+ end
17
+
18
+ def find_f(path, pattern)
19
+ Find.find(path) do |f|
20
+ return f if File.fnmatch?(pattern, File.basename(f))
21
+ end
22
+ nil
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ require 'thor'
2
+
3
+ module <%= @params[:constant_name] %>
4
+ class CLI < Thor
5
+ desc "compile", "compile all js, css, and html into a single file"
6
+ def compile()
7
+ app = RubyHtmlApp::HtmlApp.new('<%= @params[:name] %>').compile_resources
8
+ end
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ %p Hello World
@@ -0,0 +1,9 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title= title ||= ""
5
+ :javascript
6
+ #{inline_js}
7
+ :css
8
+ #{inline_css}
9
+ %body= yield
@@ -0,0 +1,6 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file. It's not advisable to add code directly here, but if you do, it'll appear
4
+ // at the bottom of the the compiled file.
5
+ //
6
+ //= require_tree .
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require '<%=@params[:name]%>/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = <%=@params[:name].inspect%>
8
+ spec.version = <%=@params[:constant_name]%>::VERSION
9
+ spec.authors = [<%=@params[:author].inspect%>]
10
+ spec.email = [<%=@params[:email].inspect%>]
11
+ spec.description = %q{TODO: Write a gem description}
12
+ spec.summary = %q{TODO: Write a gem summary}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ <% if @params[:test] -%>
24
+ spec.add_development_dependency "<%=@params[:test]%>"
25
+ <% end -%>
26
+ spec.add_dependency "rubyhtmlapp", "~> 0.0.1"
27
+ spec.add_dependency "thor", "~> 0.18.1"
28
+ spec.add_dependency "sass", "~> 3.2.8"
29
+ spec.add_dependency "haml", "~> 4.0.2"
30
+ end
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ require 'rubyhtmlapp'
3
+ require '<%=@params[:name]%>/version'
4
+ require '<%=@params[:name]%>/cli'
5
+
6
+ <%- @params[:constant_array].each_with_index do |c,i| -%>
7
+ <%= ' '*i %>module <%= c %>
8
+ <%- end -%>
9
+ <%= ' '*@params[:constant_array].size %># Your code goes here...
10
+ <%- (@params[:constant_array].size-1).downto(0) do |i| -%>
11
+ <%= ' '*i %>end
12
+ <%- end -%>
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require '<%= @params[:name] %>'
5
+
6
+ <%= @params[:constant_name] %>::CLI.start(ARGV)
@@ -0,0 +1,9 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directo\
3
+ ry
4
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear\
5
+ at
6
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
7
+ *= require_self
8
+ *= require_tree .
9
+ */
@@ -0,0 +1,3 @@
1
+ module RubyHtmlApp
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyhtmlapp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Curtis Bissonnette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tilt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: sprockets
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.9.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: templater
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.18.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.18.1
111
+ description: Creates an inlined html app using sprockets and tilt
112
+ email:
113
+ - cbissonnette@gmail.com
114
+ executables:
115
+ - rubyhtmlapp
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - RubyHtmlApp.gemspec
125
+ - bin/rubyhtmlapp
126
+ - lib/RubyHtmlApp.rb
127
+ - lib/RubyHtmlApp/cli.rb
128
+ - lib/RubyHtmlApp/helpers.rb
129
+ - lib/RubyHtmlApp/templates/cli.rb
130
+ - lib/RubyHtmlApp/templates/html/application.html.haml
131
+ - lib/RubyHtmlApp/templates/html/layout.html.haml
132
+ - lib/RubyHtmlApp/templates/javascripts/application.js
133
+ - lib/RubyHtmlApp/templates/newgem.gemspec
134
+ - lib/RubyHtmlApp/templates/newgem.rb
135
+ - lib/RubyHtmlApp/templates/run
136
+ - lib/RubyHtmlApp/templates/stylesheets/application.css.scss
137
+ - lib/RubyHtmlApp/version.rb
138
+ homepage: ''
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.0.0
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: A simple generator used to setup a project for sprockets and tilt which will
162
+ compile all source files into a single html file
163
+ test_files: []