jail 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Jail
2
2
 
3
- Copying, pasting, 'curling', running after all those jquery-plugin files, trying to keep track, loosing them, pulling your hair off. This must stop !
4
- Put all your jquery plugins (or any other assets) in rails once and for all.
5
- And if you want to free them, just open the gate.
3
+ Found a nice Jquery plugin you'd like to try out ? Now starts the RSIs :
4
+ Download, unpack, find the source files, open your app folder, drag in the javascript folder, drag in the stylesheet folder, drag in the images folder... Oh but wait, there's a better version of (modal/fancybox/slider/datepicker...). Download, unpack, find the source... _This must stop !_
5
+
6
+ Meet Jail : it puts all your Javascripts (& cie) in Rails, with just a click!
7
+
8
+ **NOW** With the 158 (sept/12) [CDNJS libraries](/cdnjs/cdnjs).
6
9
 
7
10
  ## Install
8
11
 
@@ -18,24 +21,26 @@ http://localhost:3000/jail/
18
21
 
19
22
  Chose a plugin, follow the link, Install. You're done.
20
23
 
24
+
21
25
  ![jail](/charly/jail/raw/master/jail.png)
22
26
 
23
27
  ---
24
28
 
25
- Oh no wait you still have to add :
29
+ Oh wait you might have to add :
26
30
 
27
31
  //=require myplugin.js
28
32
 
29
- Oh & you're not happy with the actual set of Jquery plugins proposed. Add your own!
33
+ And if you're not happy with the actual set of Jquery plugins proposed. Add your own!
30
34
 
31
35
  config/initializers/jail.rb
32
36
 
33
37
  module Jail
34
38
  LOGIN = 'login:password' #optional
35
- Github.add_githublist(Rails.root.join("config/jail.backboneplugins.yml"))
36
- Github.add_githublist(Rails.root.join("config/jail.whatever.yml"))
39
+ Jail::Github.add_githublist(Rails.root.join("config/jail.backboneplugins.yml"))
40
+ Jail::Github.add_githublist(Rails.root.join("config/jail.whatever.yml"))
37
41
  end
38
42
 
43
+ Buth the list is bound to grow quickly.
39
44
 
40
45
  ## Usage (alt)
41
46
 
@@ -48,7 +53,7 @@ But it must exist in the yaml file !!!
48
53
 
49
54
  ## Contribute
50
55
 
51
- The list of plugins are in a yaml file : config/prisoners.yml
56
+ The list of plugins are in a yaml file : config/jail.jqueryplugins.yml
52
57
  Add more plugins and pull a request!
53
58
  Would it be better to have them in the db ?
54
59
 
@@ -57,13 +62,21 @@ Would it be better to have them in the db ?
57
62
 
58
63
  Other approaches where :
59
64
  - 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.
60
- - 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).
65
+ - 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). **update** : it has one (of course)!
61
66
 
62
67
  ## TODO
63
68
 
64
- - plugin installed? (check file existence)
65
- - plugin outdated? (overkill ?)
66
- - bin/jail
69
+ - Pjax for laoding plugin
70
+ - plugin installed? (check file existence)
71
+ - plugin outdated? (overkill ?)
72
+ - bin/jail
73
+
74
+ ## Changelog
75
+
76
+ - 0.1.1 CDNJS Integration + Some Github Refactoring
77
+
78
+ ## Thanks to
67
79
 
80
+ - [Walter Davis](/walterdavis) for suggesting the awesome idea of including the cdnjs library.
68
81
 
69
82
  This project rocks and uses MIT-LICENSE.
@@ -12,7 +12,9 @@
12
12
  *= require_tree .
13
13
  */
14
14
 
15
- body, div { margin: 0; padding:0;}
15
+ body, div {
16
+ font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
17
+ margin: 0; padding:0;}
16
18
 
17
19
 
18
20
  #header, #page, #footer {
@@ -25,28 +27,41 @@ body, div { margin: 0; padding:0;}
25
27
  background-color: #444}
26
28
 
27
29
  #header a {
30
+ text-decoration: none;
28
31
  color: #EEE;}
29
32
 
33
+ fieldset {
34
+ color: #444;
35
+ background-color: #CCC}
36
+
37
+ legend {
38
+ padding: 3px 9px;
39
+ color: #CCC;
40
+ background-color: #444;
41
+ border: thin solid #222;
42
+ }
43
+
44
+ .smaller {
45
+ font-size: .7em;}
46
+
30
47
  .notice {
31
48
  text-align: center;
32
49
  background-color: #BCED91;
33
50
  border: thin solid #629632;
34
51
  color:; #629632;
35
- padding: 18px;
36
- }
52
+ padding: 18px;}
37
53
 
38
54
  ul.jaillinks {
39
55
  width: 400px;
40
- list-style: none;
41
- }
56
+ list-style: none;}
42
57
 
43
58
  ul.jaillinks li a {
44
59
  color: #777;
45
60
  display: block;
46
61
  text-decoration: none;
47
62
  padding: 6px;
48
- border-bottom: thin dashed #DDD;
49
- }
63
+ border-bottom: thin dashed #DDD;}
64
+
50
65
  ul.jaillinks li a:hover {
51
66
  background-color: #DDD}
52
67
 
@@ -0,0 +1,20 @@
1
+ require_dependency "jail/application_controller"
2
+
3
+ module Jail
4
+ class CdnjsController < ApplicationController
5
+ def index
6
+ @cdnjs = Cdnjs.libs.map(&:name)
7
+ end
8
+
9
+ def show
10
+ @cdnjs = Cdnjs.find(params[:name])
11
+ end
12
+
13
+ def install
14
+ @cdnjs = Cdnjs.find(params[:name])
15
+ @cdnjs.install(params["files"])
16
+
17
+ redirect_to( "/jail/cdnjs/#{params[:name]}", :notice => "Installed!" )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,68 @@
1
+ module Jail
2
+ class Cdnjs
3
+ attr_reader :github, :root_path, :package_path
4
+ delegate :name, :filename, :version, :description,
5
+ :homepage, :repositories, :maintainers, :to => :package #etc
6
+
7
+ def self.github
8
+ @github ||= Jail::Github.find("cdnjs", "cdnjs", "ajax/libs")
9
+ end
10
+
11
+ def self.libs
12
+ @libs ||= github.contents
13
+ end
14
+ libs # load & memoize cdnjs libraries
15
+
16
+ def self.lib(path)
17
+ github.where(path).contents
18
+ end
19
+
20
+ def self.find_path(name)
21
+ hash = libs.find { |hashie| hashie.path.split("/").last == name }
22
+ hash and hash.path # raise if not found ?
23
+ end
24
+
25
+ def self.find(name)
26
+ path = find_path(name)
27
+ lib = lib(path)
28
+
29
+ self.new(path, lib)
30
+ end
31
+
32
+ def initialize(path, lib)
33
+ @github = self.class.github
34
+ @root_path = path
35
+ @package_path = lib.find {|h| h.type == "file"}.path
36
+ end
37
+
38
+ def package
39
+ @package ||= Hashie::Mash.new ActiveSupport::JSON.decode( github.where(package_path).read )
40
+ end
41
+
42
+ # gets the version from the package.json & returns a path
43
+ def version_path
44
+ Pathname(root_path).join(version)
45
+ end
46
+
47
+ def files
48
+ @files ||= github.where(version_path).contents
49
+ end
50
+
51
+ def file(name)
52
+ github.where(version_path.join(name))
53
+ end
54
+
55
+ def mapped_files
56
+ files.map(&:name).group_by {|name| Pathname(name).extname }
57
+ end
58
+
59
+ def install(params)
60
+ files_to_write = params.map {|file, num| file if num == "1"}.compact!
61
+
62
+ files_to_write.each do |name|
63
+ file(name).download()
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -1,7 +1,8 @@
1
1
  module Jail
2
2
  # This is a wrapper around ::Github
3
3
  class Github
4
- attr_accessor :github, :name, :repo, :path, :spec
4
+ attr_reader :github, :name, :repo, :spec
5
+ attr_accessor :path
5
6
  cattr_accessor :githublist
6
7
 
7
8
  def self.add_githublist(yaml_path)
@@ -10,33 +11,38 @@ module Jail
10
11
  end
11
12
 
12
13
  self.githublist={}
13
- add_githublist(Jail::Engine.root.join("config", "jail.jqueryplugins.yml"))
14
+ add_githublist( Jail::Engine.root.join("config", "jail.jqueryplugins.yml") )
14
15
 
15
16
  # TODO : raise if missing descr:
16
17
  def self.all
17
18
  githublist.group_by {|k, v| v[:descr].match(/\w+:/).to_s if v[:descr]}
18
19
  end
19
20
 
20
- # Use this to initialize Github
21
- def self.find(aname, arepo, apath = nil)
22
- self.new.tap do |yo|
23
- yo.name= aname
24
- yo.repo= arepo
25
- yo.path= apath
26
- yo.spec= githublist["#{yo.name}/#{yo.repo}"]
21
+ # Uhh useless ? Or AR Sexy ?
22
+ def self.find(name, repo, path = nil)
23
+ new(name, repo).tap do |yo|
24
+ yo.path= path
27
25
  end
28
26
  end
29
27
 
30
- # Sets github attr which holds the Github (API) instance
31
- # used by repo, contents, readme etc
32
- def initialize
33
- @github = defined?(Jail::LOGIN) ?
28
+ def initialize(name, repo)
29
+ @name= name
30
+ @repo= repo
31
+ @spec= self.class.githublist["#{@name}/#{@repo}"]
32
+ @github = defined?(Jail::LOGIN) ?
34
33
  ::Github.new({ :basic_auth => Jail::LOGIN }) :
35
34
  ::Github.new
36
35
  end
37
36
 
37
+ # another AR alike for chaining
38
+ def where(path)
39
+ self.path= path
40
+ self
41
+ end
42
+
43
+ # do I need this method ?
38
44
  def repos
39
- github.repos.get(name, repo)
45
+ @repos ||= github.repos.get(name, repo)
40
46
  end
41
47
 
42
48
  def contents
@@ -50,49 +56,53 @@ module Jail
50
56
  github.markdown.render :text => text
51
57
  end
52
58
 
53
- # TODO : raise error if path's not a file
54
- def read(apath)
55
- self.path= apath
59
+ def read
60
+ #raise "blah" unless contents.type == "file"
56
61
  text = Base64.decode64 contents.content
57
62
  end
58
63
 
59
- def install
60
- #contents._links[:git]
61
- download(:js)
62
- download(:css)
63
- download(:img)
64
- end
65
-
66
- def remove
67
- delete_file(:js)
68
- delete_file(:css)
69
- delete_file(:img)
70
- end
71
-
72
- private
73
- def download(type = :js)
74
- return if spec[type].blank?
75
- text = read(spec[type])
76
- target(type).open('w') {|f| f.write(text) }
64
+ def download(type = nil)
65
+ target(type).open('w') {|f| f.write( read ) }
77
66
  end
78
67
 
79
- def delete_file(type = :js)
80
- return if spec[type].blank?
81
- self.path = spec[type]
68
+ def delete(type = nil)
82
69
  t = target(type) and t.exist? and t.delete
83
70
  end
84
71
 
85
- def target(type)
86
- filename= Pathname(path).basename.to_s
72
+ def target(type=nil)
73
+ filename= Pathname(path).basename
74
+ type = type || extract_type(filename)
75
+
87
76
  case type
88
- when :js
77
+ when :js, :coffee
89
78
  Rails.root.join("vendor/assets/javascripts/#{filename}")
90
- when :css
79
+ when :css, :scss, :less
91
80
  Rails.root.join("vendor/assets/stylesheets/#{filename}")
92
- when :img
81
+ when :img, :png, :gif, :jpeg
93
82
  Rails.root.join("vendor/assets/images/#{filename}")
94
83
  end
95
84
  end
96
85
 
86
+ def extract_type(filename)
87
+ type = Pathname(filename).extname
88
+ type = type.gsub(/\./, "").to_sym
89
+ end
90
+
91
+ #
92
+ # Depends on yaml files: dont use elsewhere
93
+ #
94
+ def write_all
95
+ [:js, :css, :img].each do |type|
96
+ where(spec[type]).download(type) if spec[type]
97
+ end
98
+ end
99
+ alias install write_all
100
+
101
+ def delete_all
102
+ [:js, :css, :img].each do |type|
103
+ where(spec[type]).delete(type) if spec[type]
104
+ end
105
+ end
106
+ alias remove delete_all
97
107
  end
98
108
  end
@@ -0,0 +1,6 @@
1
+ <%- @cdnjs.mapped_files.each do |ext, n_files| %>
2
+ <p><%= ext %></p>
3
+ <%- n_files.each do |file| %>
4
+ <br><%= file %>
5
+ <% end %>
6
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <%#=debug @cdnjs %>
2
+
3
+ <h1>
4
+ <%= link_to "CDNJS", "https://github.com/cdnjs/cdnjs" %> List of Javascripts Libraries
5
+ </h1>
6
+
7
+ <ul class='jaillinks'>
8
+ <%- @cdnjs.each do |name| %>
9
+ <li><%= link_to name, "/jail/cdnjs/#{name}" %></li>
10
+ <% end %>
11
+ </ul>
@@ -0,0 +1,26 @@
1
+ <%- if flash[:notice] %>
2
+ <div class='notice'>
3
+ <%= flash[:notice] %>
4
+ </div>
5
+ <% end %>
6
+
7
+ <h1><%= @cdnjs.name %></h1>
8
+ <p><%= @cdnjs.description %></p>
9
+
10
+ <%= form_tag "/jail/cdnjs/#{@cdnjs.name}" do %>
11
+ <fieldset>
12
+ <legend>Files To Install (uncheck unnecesseray)</legend>
13
+ <%- @cdnjs.files.map(&:name).each do |name| %>
14
+ <p>
15
+ <%= label_tag name %>
16
+ <%= check_box('files', name, {:checked => true}, checked_value="1", unchecked_value="0") %>
17
+ </p>
18
+ <% end %>
19
+ <%= submit_tag "Install" %>
20
+ </fieldset>
21
+ <% end %>
22
+
23
+ <p>homepage: <%= link_to @cdnjs.homepage, @cdnjs.homepage %></p>
24
+ <%- @cdnjs.repositories.map(&:url).each do |url| %>
25
+ <p>repository : <%= link_to url, url %></p>
26
+ <% end %>
@@ -8,8 +8,16 @@
8
8
  </head>
9
9
  <body>
10
10
  <div id="header">
11
- <h1><%=link_to "Jail", root_path %></h1>
12
- Puts your assets in rails
11
+ <h1>
12
+ <%=link_to "Jail", root_path %>
13
+ <span class='smaller'> - Puts your Js in Rails</span>
14
+ </h1>
15
+ <div style="text-align: center;">
16
+ <%= link_to "Jail's list", "/jail/" %>
17
+ |
18
+ <%= link_to "Cdnjs's List", "/jail/cdnjs" %>
19
+ </div>
20
+
13
21
  </div>
14
22
 
15
23
  <div id="page">
@@ -1,10 +1,20 @@
1
1
  Jail::Engine.routes.draw do
2
2
 
3
3
  root :to => "githubs#index"
4
+ match "/cdnjs" => "cdnjs#index"
5
+ with_options(:name => /[^\/]+/ ) do |opt|
6
+ opt.match "/cdnjs/:name" => "cdnjs#show", :via => :get
7
+ opt.match "/cdnjs/:name" => "cdnjs#install", :via => :post
8
+ #opt.match "/cdnjs/:name/remove" => "cdnjs#remove"
9
+ #opt.match "/cdnjs/:name/*path" => "cdnjs#show"
10
+ end
11
+
4
12
  with_options(:repo => /[^\/]+/ ) do |opt|
5
13
  opt.match ":name/:repo" => "githubs#show"
6
14
  opt.match ":name/:repo/install" => "githubs#install"
7
15
  opt.match ":name/:repo/remove" => "githubs#remove"
8
16
  opt.match ":name/:repo/*path" => "githubs#show"
9
17
  end
18
+
19
+
10
20
  end