initjs 0.1.3 → 1.0.0
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.
- data/.gitignore +9 -10
- data/.rvmrc +1 -0
- data/.travis.yml +15 -0
- data/LICENSE.txt +2 -2
- data/README.md +176 -47
- data/initjs.gemspec +11 -4
- data/lib/assets/javascript/init.js.coffee +8 -1
- data/lib/generators/initjs/add/add_generator.rb +57 -0
- data/lib/generators/initjs/add/templates/namespaced_action.coffee +5 -0
- data/lib/generators/initjs/add/templates/simple_action.coffee +3 -0
- data/lib/generators/initjs/install/install_generator.rb +25 -0
- data/lib/generators/initjs/install/templates/app.coffee +15 -0
- data/lib/generators/initjs/resource_helpers.rb +23 -0
- data/lib/initjs/helper.rb +5 -4
- data/lib/initjs/version.rb +1 -1
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/Gemfile +10 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application-turbolinks.js +12 -0
- data/spec/dummy/app/assets/javascripts/application.js +10 -0
- data/spec/dummy/app/assets/javascripts/application.sample.js +15 -0
- data/spec/dummy/app/assets/javascripts/dummy/blog/.gitkip +0 -0
- data/spec/dummy/app/assets/javascripts/dummy/blog/posts/.gitkip +0 -0
- data/spec/dummy/app/assets/javascripts/dummy/blog/posts/index.js.coffee +6 -0
- data/spec/dummy/app/assets/javascripts/dummy/blog/posts/new.js.coffee +6 -0
- data/spec/dummy/app/assets/javascripts/dummy/blog/posts/show.js.coffee +6 -0
- data/{lib/generators/initjs/templates/app.js.coffee → spec/dummy/app/assets/javascripts/dummy/dummy.js.coffee} +4 -1
- data/spec/dummy/app/assets/javascripts/dummy/home/.gitkip +0 -0
- data/spec/dummy/app/assets/javascripts/dummy/home/index.js.coffee +4 -0
- data/spec/dummy/app/assets/javascripts/dummy/posts/.gitkip +0 -0
- data/spec/dummy/app/assets/javascripts/dummy/posts/index.js.coffee +4 -0
- data/spec/dummy/app/assets/javascripts/dummy/posts/new.js.coffee +4 -0
- data/spec/dummy/app/assets/javascripts/dummy/posts/show.js.coffee +4 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/blog/posts_controller.rb +10 -0
- data/spec/dummy/app/controllers/home_controller.rb +4 -0
- data/spec/dummy/app/controllers/posts_controller.rb +10 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/blog/posts/index.html.erb +2 -0
- data/spec/dummy/app/views/blog/posts/new.html.erb +2 -0
- data/spec/dummy/app/views/blog/posts/show.html.erb +2 -0
- data/spec/dummy/app/views/home/index.html.erb +10 -0
- data/spec/dummy/app/views/layouts/application.html.erb +24 -0
- data/spec/dummy/app/views/posts/index.html.erb +2 -0
- data/spec/dummy/app/views/posts/new.html.erb +2 -0
- data/spec/dummy/app/views/posts/show.html.erb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +54 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +8 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/features/blog_posts_spec.rb +47 -0
- data/spec/dummy/spec/features/home_spec.rb +11 -0
- data/spec/dummy/spec/features/posts_spec.rb +47 -0
- data/spec/dummy/spec/lib/generators/initjs/add_generator_spec.rb +80 -0
- data/spec/dummy/spec/lib/generators/initjs/install_generator_spec.rb +36 -0
- data/spec/dummy/spec/spec_helper.rb +33 -0
- data/spec/tmp/app/assets/javascripts/.gitkip +0 -0
- metadata +278 -10
- data/lib/generators/initjs/initjs_generator.rb +0 -11
@@ -0,0 +1,5 @@
|
|
1
|
+
<%= js_app_name %>.<%= @namespace_name.camelize %> = {} if <%= js_app_name %>.<%= @namespace_name.camelize %> is undefined
|
2
|
+
<%= js_app_name %>.<%= @namespace_name.camelize %>.<%= @controller_name.camelize %> = {} if <%= js_app_name %>.<%= @namespace_name.camelize %>.<%= @controller_name.camelize %> is undefined
|
3
|
+
|
4
|
+
<%= js_app_name %>.<%= @namespace_name.camelize %>.<%= @controller_name.camelize %>.<%= @action_name.camelize %> =->
|
5
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'generators/initjs/resource_helpers'
|
2
|
+
|
3
|
+
module Initjs
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Initjs::Generators::ResourceHelpers
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
def inject_backbone
|
11
|
+
inject_into_file "app/assets/javascripts/application.js", before: "//= require_tree" do
|
12
|
+
"//= require #{application_name.underscore}/#{application_name.underscore}.js\n//= require init.js\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_app_file
|
17
|
+
template "app.coffee", "#{application_path}/#{application_name.underscore}.js.coffee"
|
18
|
+
|
19
|
+
# Alerts
|
20
|
+
puts "\n\nInclude the Initjs tag in your application layout (usually found at app/view/layouts/application.html.erb) after the body tag."
|
21
|
+
puts "<%= initjs_tag app_name: '#{application_name}' %>"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#= require_self
|
2
|
+
#= require_tree .
|
3
|
+
|
4
|
+
window.<%= js_app_name %> =
|
5
|
+
Common:
|
6
|
+
initPage: ->
|
7
|
+
# If you're using the Turbolinks and you need run a code only one time, put something here.
|
8
|
+
# if you're not using the turbolinks, there's no difference between init and initPage.
|
9
|
+
|
10
|
+
init: ->
|
11
|
+
# Something here. This is called in every page, with or without Turbolinks.
|
12
|
+
|
13
|
+
finish: ->
|
14
|
+
# Something here. This is called in every page, with or without Turbolinks.
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Initjs
|
2
|
+
module Generators
|
3
|
+
module ResourceHelpers
|
4
|
+
|
5
|
+
def application_path
|
6
|
+
"app/assets/javascripts/#{application_name.underscore}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def application_name
|
10
|
+
if defined?(Rails) && Rails.application
|
11
|
+
Rails.application.class.name.split('::').first
|
12
|
+
else
|
13
|
+
"App"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def js_app_name
|
18
|
+
application_name.camelize
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/initjs/helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Initjs
|
2
2
|
module Helper
|
3
|
-
def initjs_tag
|
3
|
+
def initjs_tag options = {}
|
4
4
|
content_tag 'div', '', { :id => "init-js",
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
:"data-controller-class" => controller.class.name,
|
6
|
+
:"data-controller-name" => controller.controller_name.camelize,
|
7
|
+
:"data-action" => controller.action_name.camelize,
|
8
|
+
:"data-app-name" => options[:app_name] || "App"}
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
data/lib/initjs/version.rb
CHANGED
data/spec/dummy/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format doc
|
data/spec/dummy/Gemfile
ADDED
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,12 @@
|
|
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 accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require 'turbolinks'
|
10
|
+
//= require dummy/dummy.js
|
11
|
+
//= require init.js
|
12
|
+
|
@@ -0,0 +1,10 @@
|
|
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 accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require dummy/dummy.js
|
10
|
+
//= require init.js
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1>Home#index</h1>
|
2
|
+
<p>Find me in app/views/home/index.html.erb</p>
|
3
|
+
|
4
|
+
<%= link_to "Posts#index", posts_path %>
|
5
|
+
<%= link_to "Posts#new", new_post_path %>
|
6
|
+
<%= link_to "Posts#show", post_path(1) %>
|
7
|
+
|
8
|
+
<%= link_to "PostsBlog#index", blog_posts_path %>
|
9
|
+
<%= link_to "PostsBlog#new", new_blog_post_path %>
|
10
|
+
<%= link_to "PostsBlog#show", blog_post_path(1) %>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", :media => "all" %>
|
6
|
+
|
7
|
+
<%=
|
8
|
+
if params[:turbolinks]
|
9
|
+
javascript_include_tag "application-turbolinks"
|
10
|
+
else
|
11
|
+
javascript_include_tag "application"
|
12
|
+
end
|
13
|
+
%>
|
14
|
+
<%= csrf_meta_tags %>
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<%= initjs_tag app_name: "Dummy" %>
|
18
|
+
|
19
|
+
<%= link_to "Home#index", root_path %>
|
20
|
+
<%= yield %>
|
21
|
+
<div class="javascript-content"></div>
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "active_resource/railtie"
|
8
|
+
require "sprockets/railtie"
|
9
|
+
# require "rails/test_unit/railtie"
|
10
|
+
|
11
|
+
if defined?(Bundler)
|
12
|
+
# If you precompile assets before deploying to production, use this line
|
13
|
+
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
14
|
+
# If you want your assets lazily compiled in production, use this line
|
15
|
+
# Bundler.require(:default, :assets, Rails.env)
|
16
|
+
end
|
17
|
+
|
18
|
+
module Dummy
|
19
|
+
class Application < Rails::Application
|
20
|
+
# Settings in config/environments/* take precedence over those specified here.
|
21
|
+
# Application configuration should go into files in config/initializers
|
22
|
+
# -- all .rb files in that directory are automatically loaded.
|
23
|
+
|
24
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
25
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
26
|
+
|
27
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
28
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
29
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
30
|
+
|
31
|
+
# Activate observers that should always be running.
|
32
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
33
|
+
|
34
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
35
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
36
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
37
|
+
|
38
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
39
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
40
|
+
# config.i18n.default_locale = :de
|
41
|
+
|
42
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
43
|
+
config.encoding = "utf-8"
|
44
|
+
|
45
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
46
|
+
config.filter_parameters += [:password]
|
47
|
+
|
48
|
+
# Enable the asset pipeline
|
49
|
+
config.assets.enabled = true
|
50
|
+
|
51
|
+
# Version of your assets, change this if you want to expire all your assets
|
52
|
+
config.assets.version = '1.0'
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|