Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial release

  • Loading branch information...
commit 3d524c1576addd8c4ffc28cf6c0a82084055b13b 0 parents
@charly authored
4 .gitignore
@@ -0,0 +1,4 @@
+.bundle/
+log/*.log
+pkg/
+test/
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
17 Gemfile
@@ -0,0 +1,17 @@
+source "http://rubygems.org"
+
+# Declare your gem's dependencies in jail.gemspec.
+# Bundler will treat runtime dependencies like base dependencies, and
+# development dependencies will be added by default to the :development group.
+gemspec
+
+# jquery-rails is used by the dummy application
+# gem "jquery-rails"
+
+# Declare any dependencies that are still in development here instead of in
+# your gemspec. These might include edge Rails or gems from your path or
+# Git. Remember to move these dependencies to your gemspec before releasing
+# your gem to rubygems.org.
+
+# To use debugger
+# gem 'ruby-debug'
128 Gemfile.lock
@@ -0,0 +1,128 @@
+PATH
+ remote: .
+ specs:
+ jail (0.0.1)
+ github_api
+ rails (~> 3.2.8)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.2.8)
+ actionpack (= 3.2.8)
+ mail (~> 2.4.4)
+ actionpack (3.2.8)
+ activemodel (= 3.2.8)
+ activesupport (= 3.2.8)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.4)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.3)
+ activemodel (3.2.8)
+ activesupport (= 3.2.8)
+ builder (~> 3.0.0)
+ activerecord (3.2.8)
+ activemodel (= 3.2.8)
+ activesupport (= 3.2.8)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.8)
+ activemodel (= 3.2.8)
+ activesupport (= 3.2.8)
+ activesupport (3.2.8)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.3)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ faraday (0.8.4)
+ multipart-post (~> 1.1)
+ github_api (0.7.0)
+ faraday (~> 0.8.1)
+ hashie (~> 1.2.0)
+ multi_json (~> 1.3)
+ nokogiri (~> 1.5.2)
+ oauth2
+ hashie (1.2.0)
+ hike (1.2.1)
+ httpauth (0.2.0)
+ i18n (0.6.1)
+ journey (1.0.4)
+ jquery-rails (2.1.3)
+ railties (>= 3.1.0, < 5.0)
+ thor (~> 0.14)
+ json (1.7.5)
+ jwt (0.1.5)
+ multi_json (>= 1.0)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.19)
+ multi_json (1.3.6)
+ multipart-post (1.1.5)
+ nokogiri (1.5.5)
+ oauth2 (0.8.0)
+ faraday (~> 0.8)
+ httpauth (~> 0.1)
+ jwt (~> 0.1.4)
+ multi_json (~> 1.0)
+ rack (~> 1.2)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rails (3.2.8)
+ actionmailer (= 3.2.8)
+ actionpack (= 3.2.8)
+ activerecord (= 3.2.8)
+ activeresource (= 3.2.8)
+ activesupport (= 3.2.8)
+ bundler (~> 1.0)
+ railties (= 3.2.8)
+ railties (3.2.8)
+ actionpack (= 3.2.8)
+ activesupport (= 3.2.8)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (>= 0.14.6, < 2.0)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.11.0)
+ rspec-core (~> 2.11.0)
+ rspec-expectations (~> 2.11.0)
+ rspec-mocks (~> 2.11.0)
+ rspec-core (2.11.1)
+ rspec-expectations (2.11.3)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.11.3)
+ sprockets (2.1.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
+ thor (0.16.0)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jail!
+ jquery-rails
+ rspec
+ sqlite3
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright 2012 Charles Sistovaris
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 README.md
@@ -0,0 +1,56 @@
+# Jail
+
+Copying, pasting, 'curling', running after all those jquery-plugin files, trying to keep track, loosing them, pulling your hair off. This must stop !
+Put all your jquery plugins (or any other assets) in rails once and for all.
+And if you want to free them, just open the gate.
+
+## Install
+
+ gem 'jail', :group => "development"
+
+config/routes.rb
+
+ mount Jail::Engine => "/jail"
+
+## Usage
+
+http://localhost:3000/jail/
+
+Chose a plugin, follow the link, Install. You're done.
+Oh no wait you still have to add :
+
+ //=require myplugin.js
+
+
+## Usage (alt)
+
+While waiting for a bin/jail feature:
+
+ rails console
+ > Jail::Github.find("name", "repo").install
+
+But it need to exist in the yaml file !!!
+
+## Contribute
+
+The list of plugins are in a yaml file : config/prisoners.yml
+Add more plugins and pull a request!
+Would it be better to have them in the db ?
+
+
+## Why an Engine ?
+
+Other approaches where :
+ - create a gem for each jquery plugin. But that means updating the gem with the latest release of each plugin and nobody wants to keep track of dozens of repos.
+ - Do a generator instead but, while the thought came to me while writing this gem, I didn't find any remote feature in Thor (may be wrong though since rails templates has it).
+
+## TODO
+
+- remove plugin
+- plugin installed? (check file existence)
+- plugin outdated? (overkill ?)
+- clean routes
+- bin/jail
+
+
+This project rocks and uses MIT-LICENSE.
40 Rakefile
@@ -0,0 +1,40 @@
+#!/usr/bin/env rake
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
+
+RDoc::Task.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Jail'
+ rdoc.options << '--line-numbers'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
+load 'rails/tasks/engine.rake'
+
+
+
+Bundler::GemHelper.install_tasks
+
+require 'rake/testtask'
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+
+task :default => :test
0  app/assets/images/jail/.gitkeep
No changes.
15 app/assets/javascripts/jail/application.js
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
28 app/assets/stylesheets/jail/application.css
@@ -0,0 +1,28 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+ */
+
+body, div { margin: 0; padding:0;}
+
+
+#header, #page, #footer {
+ width: 960px;
+ margin: 0 auto;
+ padding: 9px;}
+
+#header {
+ color: #CCC;
+ background-color: #444}
+
+#header a {
+ color: #EEE;}
4 app/controllers/jail/application_controller.rb
@@ -0,0 +1,4 @@
+module Jail
+ class ApplicationController < ActionController::Base
+ end
+end
20 app/controllers/jail/githubs_controller.rb
@@ -0,0 +1,20 @@
+require_dependency "jail/application_controller"
+
+module Jail
+ class GithubsController < ApplicationController
+ def index
+ @githubs = Github.all
+ end
+
+ def show
+ @github = Github.find(params[:name], params[:repo], params[:path])
+ end
+
+ def install
+ @github = Github.find(params[:name], params[:repo])
+ @github.install
+ redirect_to root_path
+ end
+
+ end
+end
75 app/models/jail/github.rb
@@ -0,0 +1,75 @@
+module Jail
+ # This is a wrapper around ::Github
+ class Github
+ attr_accessor :github, :name, :repo, :path, :spec
+
+ # not memoizing for now
+ def self.githublist
+ @githublist = ::YAML.load_file(Jail::Engine.root.join("config", "jqplugins.yml")).to_hash
+ end
+
+ def self.all
+ githublist.keys
+ end
+
+ # Use this to initialize Github
+ def self.find(aname = "harvesthq", arepo = "chosen", apath = nil)
+ self.new.tap do |yo|
+ yo.name= aname
+ yo.repo= arepo
+ yo.path= apath
+ yo.spec= githublist["#{yo.name}/#{yo.repo}"]
+ end
+ end
+
+ # Sets github attr which holds the Github (API) instance
+ # used by repo, contents, readme etc
+ def initialize
+ @github = defined?(Jail::LOGIN) ?
+ ::Github.new({ :basic_auth => Jail::LOGIN }) :
+ ::Github.new
+ end
+
+ def repos
+ github.repos.get(name, repo)
+ end
+
+ def contents
+ self.path ||= "/"
+ github.repos.contents.get(name, repo, path)
+ end
+
+ def readme
+ text = Base64.decode64 github.repos.contents.readme(name, repo).content
+ github.markdown.render :text => text
+ end
+
+ def install
+ #contents._links[:git]
+ download(:js)
+ download(:css)
+ download(:img)
+ end
+
+ private
+ def download(type = :js)
+ return if spec[type].blank?
+ self.path= spec[type]
+ text = Base64.decode64 contents.content
+ target(type).open('w') {|f| f.write(text)}
+ end
+
+ def target(type)
+ filename= Pathname(path).basename.to_s
+ case type
+ when :js
+ Rails.root.join("vendor/assets/javascripts/#{filename}")
+ when :css
+ Rails.root.join("vendor/assets/stylesheets/#{filename}")
+ when :img
+ Rails.root.join("vendor/assets/images/#{filename}")
+ end
+ end
+
+ end
+end
10 app/views/jail/githubs/index.html.erb
@@ -0,0 +1,10 @@
+
+<%# @githubs.each do |jqgithub| %>
+<ul>
+ <%- @githubs.each do |k| %>
+ <li><%= link_to "#{k}", k %></li>
+ <% end %>
+</ul>
+
+
+
10 app/views/jail/githubs/show.html.erb
@@ -0,0 +1,10 @@
+
+<h2><%=link_to "install", request.url + "/install" %></h2>
+<ul>
+ <%- @github.contents.each do |cont| %>
+ <li><%= link_to cont.name, cont._links[:html] %></li>
+ <% end %>
+</ul>
+
+
+<%=raw @github.readme %>
20 app/views/layouts/jail/application.html.erb
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Jail</title>
+ <%= stylesheet_link_tag "jail/application", :media => "all" %>
+ <%#= javascript_include_tag "jail/application" %>
+ <%#= csrf_meta_tags %>
+</head>
+<body>
+ <div id="header">
+ <h1><%=link_to "Jail", root_path %></h1>
+ Puts your assets in rails
+ </div>
+
+ <div id="page">
+ <%= yield %>
+ </div>
+
+</body>
+</html>
36 config/prisoners.yml
@@ -0,0 +1,36 @@
+
+# Forms
+simsalabim/sisyphus:
+ :js: ""
+ :css: ""
+ :descr: "form:"
+ivaynberg/select2:
+ :js: "select2.js"
+ :css: "select2.css"
+ :descr: "form:"
+devluis/ddslick:
+ :js: "js/ddslick.js"
+ :descr: "form:"
+
+# Images
+tapmodo/Jcrop:
+ :js: "js/jquery.Jcrop.js"
+ :css: "css/jquery.Jcrop.css"
+ :img: "css/Jcrop.gif"
+ :descr: "image:"
+
+# Map
+hpneo/gmaps:
+ :js: "gmaps.js"
+ :descr: "map:"
+
+# Essentials
+scotthamper/cookies:
+ :js: "cookies.js"
+ :descr: "essentials:"
+
+# Yup
+arturadib/strapdown:
+ :js: "src/strapdown.js"
+ :css: "src/strapdown.css"
+ :desc: ""
7 config/routes.rb
@@ -0,0 +1,7 @@
+Jail::Engine.routes.draw do
+
+ root :to => "githubs#index"
+ match ":name/:repo" => "githubs#show"
+ match ":name/:repo/install" => "githubs#install"
+ match ":name/:repo/*path" => "githubs#show"
+end
29 jail.gemspec
@@ -0,0 +1,29 @@
+$:.push File.expand_path("../lib", __FILE__)
+
+# Maintain your gem's version:
+require "jail/version"
+
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+ s.name = "jail"
+ s.version = Jail::VERSION
+ s.authors = ["Charles Sistovaris"]
+ s.email = ["charlysisto@gmail.com"]
+ s.homepage = "http://github/charly/jail"
+ s.summary = "Puts your assets in rails"
+ s.description = %Q{
+ Developers facility to install or remove jQuery plugins hosted on github by
+ adding proper javascripts, stylesheets and images in vendor/assets.
+ }
+
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.test_files = Dir["test/**/*"]
+
+ s.add_dependency "rails", "~> 3.2.8"
+ s.add_dependency "github_api"
+ # s.add_dependency "jquery-rails"
+
+ s.add_development_dependency "rspec"
+ s.add_development_dependency "sqlite3"
+ s.add_development_dependency "jquery-rails"
+end
6 lib/jail.rb
@@ -0,0 +1,6 @@
+require "rubygems"
+require "jail/engine"
+require "github_api"
+
+module Jail
+end
5 lib/jail/engine.rb
@@ -0,0 +1,5 @@
+module Jail
+ class Engine < ::Rails::Engine
+ isolate_namespace Jail
+ end
+end
3  lib/jail/version.rb
@@ -0,0 +1,3 @@
+module Jail
+ VERSION = "0.0.1"
+end
4 lib/tasks/jail_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :jail do
+# # Task goes here
+# end
8 script/rails
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+ENGINE_ROOT = File.expand_path('../..', __FILE__)
+ENGINE_PATH = File.expand_path('../../lib/jail/engine', __FILE__)
+
+require 'rails/all'
+require 'rails/engine/commands'
47 spec/models/github_spec.rb
@@ -0,0 +1,47 @@
+require "spec_helper"
+
+# TODO : TAFT
+decribe Jail::Github do
+
+ describe "#github" do
+ it "holds a Github instance" do
+ true
+ end
+ end
+
+ describe "#repos" do
+ it "holds a Github::Repo instance" do
+ true
+ end
+
+ end
+
+ describe "#contents" do
+ it "holds a Github::Content instance" do
+ true
+ end
+
+ end
+
+ describe "#install" do
+ it "calls download 3 times instance" do
+ true
+ end
+
+ end
+
+ describe "#download" do
+ it "gets content from the filename instance" do
+ true
+ end
+
+ end
+
+ describe "#target" do
+ it "holds sets a Pathanme" do
+ true
+ end
+
+ end
+
+end
17 spec/spec_helper.rb
@@ -0,0 +1,17 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = 'random'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.