endymion-ginsu 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,13 @@
1
+ Ginsu
2
+ =====
3
+
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) 2009 [name of plugin creator], released under the MIT license
data/README.textile CHANGED
@@ -24,22 +24,28 @@ Copy your static web into your Rails application's new "static" directory. If y
24
24
  Configure Ginsu to slice sections of pages from the static web site into partial templates in your Rails application by adding slicing instructions to your config/initializers/ginsu.rb:
25
25
 
26
26
  <pre><code># Create a 'header' partial by plucking header HTML from static/index.html using a CSS selector.
27
- slice :css => 'h3.r a.l', :static => 'index.html', :partial => 'header'
27
+ configure.slices << { :css => 'h3.r a.l', :static => 'index.html', :partial => 'header' }
28
28
 
29
29
  # Create a 'header' partial by plucking header HTML from static/index.html using an xpath selector.
30
- slice :xpath => '//h3/a[@class="l"]', :static => 'index.html', :partial => 'header'
30
+ configure.slices << { slice :xpath => '//h3/a[@class="l"]', :static => 'index.html', :partial => 'header' }
31
31
 
32
32
  # Just use the 'search' parameter to use either CSS or xpath.
33
- slice :search => 'h3.r a.l', :static => 'index.html', :partial => 'header'
34
- slice :search => '//h3/a[@class="m"]', :static => 'index.html', :partial => 'header'</pre></code>
33
+ configure.slices << { :search => 'h3.r a.l', :static => 'index.html', :partial => 'header' }
34
+ configure.slices << { :search => '//h3/a[@class="m"]', :static => 'index.html', :partial => 'header' }
35
+
36
+ # Create symbolic links in the public/ directory of the Rails app for selected sections and files.
37
+ configure.links << { :static => 'galleries' }
38
+ configure.links << { :static => 'events' }
39
+ configure.links << { :static => 'holdout.html' }
40
+ </pre></code>
35
41
 
36
42
  Now when you run:
37
43
 
38
- rake ginsu:update
44
+ rake ginsu:slice
39
45
 
40
46
  ...Ginsu will find the header in your static/index.html file and create a partial in app/views/_header.html.erb with the contents of the HTML element that it locates using your CSS or xpath selector.
41
47
 
42
- Using this technique does not require your graphic designer to make any changes to the Dreamweaver project. You don't have to tag the section that you want to slice out, you simply describe where it's located and Ginsu will find it and slice it out.
48
+ Using this technique does not require your graphic designer to make any changes to the Dreamweaver project. You don't have to tag the section that you want to slice out, you simply describe where it's located and Ginsu will find it and slice it out. You bring your graphic designers into the agile process by enabling them to update parts of the web site with their tools, without learning Rails.
43
49
 
44
50
  h2. Installation
45
51
 
@@ -54,9 +60,9 @@ Make sure that you have the gem:
54
60
 
55
61
  rake gems:install
56
62
 
57
- Create your initializer, for configuring Ginsu:
63
+ Generate your initializer, for configuring Ginsu:
58
64
 
59
- rake ginsu:setup
65
+ script/generate ginsu
60
66
 
61
67
  Optionally, you can vendor the gem:
62
68
 
@@ -66,6 +72,22 @@ h2. Configure
66
72
 
67
73
  The Ginsu configuration is in the initializer file config/initializers/ginsu.rb:
68
74
 
75
+ <pre><code>require 'ginsu'
76
+ Ginsu::Knife.configure do |configure|
77
+
78
+ # The default location of the static web site is 'site', but maybe your static
79
+ # site includes 150 MB worth of Photoshop .psd files and you don't want those
80
+ # in your Capistrano deployments. Change the source path here if you want.
81
+ config.source = '/home/webproject/site'
82
+
83
+ config.slices << { :search => '#header', :static => 'index.html', :partial => 'header' }
84
+ config.slices << { :search => '#footer', :static => 'index.html', :partial => 'footer' }
85
+
86
+ config.links << { :static => 'galleries' }
87
+ config.links << { :static => 'news' }
88
+
89
+ end</code></pre>
90
+
69
91
  h2. Features
70
92
 
71
93
  h3. slice
@@ -74,4 +96,4 @@ A slice is the content of an HTML element that Ginsu will slice out of a static
74
96
 
75
97
  h3. link
76
98
 
77
- A link is a page or a folder that you want to be entirely served as static content. Ginsu will create symbolic links in your Rails application's public/ directory for each link.
99
+ A link is a page or a folder that you want to be entirely served as static content. Ginsu will create symbolic links in your Rails application's public/ directory for each link.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the Ginsu initializer in config/intitializers/ginsu.rb
3
+
4
+ Example:
5
+ ./script/generate ginsu
6
+
7
+ This will create:
8
+ config/initializers/ginsu.rb
@@ -0,0 +1,7 @@
1
+ class GinsuGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.template 'config/initializers/ginsu.rb', 'config/initializers/ginsu.rb'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'ginsu'
2
+ Ginsu::Knife.configure do |configure|
3
+
4
+ # The default location of the static web site is 'site', but maybe your static
5
+ # site includes 150 MB worth of Photoshop .psd files and you don't want those
6
+ # in your Capistrano deployments. Change the source path here if you want.
7
+ # config.source = '/home/webproject/site'
8
+
9
+ # config.slices << { :search => '#header', :static => 'index.html', :partial => 'header' }
10
+ # config.slices << { :search => '#footer', :static => 'index.html', :partial => 'footer' }
11
+
12
+ # config.links << { :static => 'galleries' }
13
+ # config.links << { :static => 'news' }
14
+
15
+ end
data/ginsu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ginsu}
5
- s.version = "0.0.0"
5
+ s.version = "0.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Porter"]
@@ -10,17 +10,24 @@ Gem::Specification.new do |s|
10
10
  s.description = %q{Ginsu is a Ruby on Rails plugin for carving partials out of static web sites, for including graphic designers in the agile process for developing a web project.}
11
11
  s.email = %q{rap@endymion.com}
12
12
  s.extra_rdoc_files = [
13
- "README.textile"
13
+ "README",
14
+ "README.textile"
14
15
  ]
15
16
  s.files = [
16
17
  "MIT-LICENSE",
18
+ "README",
17
19
  "README.textile",
18
20
  "Rakefile",
19
21
  "VERSION",
22
+ "generators/ginsu/USAGE",
23
+ "generators/ginsu/ginsu_generator.rb",
24
+ "generators/ginsu/templates/config/initializers/ginsu.rb",
20
25
  "ginsu.gemspec",
21
26
  "init.rb",
22
27
  "install.rb",
23
28
  "lib/ginsu.rb",
29
+ "lib/ginsu/config.rb",
30
+ "lib/ginsu/knife.rb",
24
31
  "tasks/ginsu_tasks.rake",
25
32
  "test/ginsu_test.rb",
26
33
  "test/test_helper.rb",
data/lib/ginsu.rb CHANGED
@@ -1 +1,12 @@
1
- # Ginsu
1
+ module Ginsu; end
2
+
3
+ require('rubygems')
4
+
5
+ require('nokogiri')
6
+
7
+ def require_local(suffix)
8
+ require(File.expand_path(File.join(File.dirname(__FILE__), suffix)))
9
+ end
10
+
11
+ require_local('ginsu/knife')
12
+ require_local('ginsu/config')
@@ -0,0 +1,41 @@
1
+ # config.rb contains classes, methods and extends existing Ginsu classes
2
+ # to provide easy configuration facilities.
3
+
4
+ module Ginsu
5
+ # Represents global configuration for Ginsu::Knife.
6
+ # Can override the following configuration options:
7
+ # * <tt>source</tt> - the source directory of the static web site. Defaults to 'static'.
8
+ class Config
9
+ @@ATTRIBUTES = [
10
+ :source,
11
+ :slices,
12
+ :links
13
+ ]
14
+ attr_accessor *@@ATTRIBUTES
15
+
16
+ def initialize(params = {})
17
+ params.each do |key,val|
18
+ self.send("#{key}=", val) if self.respond_to? key
19
+ end
20
+ self.send(:init) if self.respond_to? :init
21
+ end
22
+
23
+ end
24
+
25
+ class Knife
26
+ @@defaults = {
27
+ :source => 'static',
28
+ :slices => [],
29
+ :links => []
30
+ }
31
+ @@config = Ginsu::Config.new(@@defaults)
32
+
33
+ class << self
34
+ # Yields to given <tt>block</tt> to configure the Ginsu.
35
+ def configure(&block)
36
+ raise ArgumentError, "Block must be provided to configure" unless block_given?
37
+ yield @@config
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,62 @@
1
+ require 'nokogiri'
2
+
3
+ module Ginsu
4
+ class Knife
5
+
6
+ def self.slice
7
+ @@config.slices.each do |slice|
8
+
9
+ puts "Each slice requires a :static parameter to specify the source file." if
10
+ slice[:static].blank?
11
+ puts "Each slice requires either a :search, :css or :xpath parameter with a search string." if
12
+ slice[:css].blank? and slice[:xpath].blank? and slice[:search].blank?
13
+ puts "Each slice requires a :partial parameter with the name of the destination template." if
14
+ slice[:partial].blank?
15
+
16
+ # Open the static source HTML file.
17
+ static_source_string = ''
18
+ static_source_path = File.join(@@config.source, slice[:static])
19
+ File.open(static_source_path, "r") { |f|
20
+ static_source_string = f.read
21
+ }
22
+ static_source = Nokogiri::HTML(static_source_string)
23
+
24
+ # Use Nokogiri to slice out the desired element's content.
25
+ found = ''
26
+ if slice[:css]
27
+ found = static_source.css(slice[:css]).first
28
+ elsif slice[:xpath]
29
+ found = static_source.css(slice[:xpath]).first
30
+ else
31
+ found = static_source.search(slice[:search]).first
32
+ end
33
+
34
+ # Drop that found string into the appropriate partial.
35
+ partial_filename = slice[:partial]
36
+ partial_filename = '_' + partial_filename unless partial_filename =~ /^[^\_]/
37
+ partial_filename += '.html.erb' unless partial_filename =~ /\./
38
+ partial_filename = File.join('app/views/', partial_filename)
39
+ puts "Sliced partial '#{partial_filename}' from static '#{static_source_path}'."
40
+ File.open(partial_filename, 'w') {|f| f.write(found) }
41
+
42
+ end
43
+ end
44
+
45
+ def self.link
46
+ @@config.links.each do |link|
47
+
48
+ puts "Each link requires a :static parameter with the name of the static resource" +
49
+ " to link to the public/ directory in your Rails application." if
50
+ link[:static].blank?
51
+
52
+ source = File.join(FileUtils.pwd, @@config.source, link[:static])
53
+ destination = File.join('public', link[:static])
54
+
55
+ puts "Linking '#{source}' to '#{destination}'."
56
+ FileUtils.ln_s source, destination, :force => true
57
+
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -1,4 +1,7 @@
1
- # desc "Explaining what the task does"
2
- # task :ginsu do
3
- # # Task goes here
4
- # end
1
+ namespace :ginsu do
2
+ desc "Update Rails application from static web site source."
3
+ task :slice => :environment do
4
+ Ginsu::Knife.link
5
+ Ginsu::Knife.slice
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: endymion-ginsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Porter
@@ -20,16 +20,23 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
+ - README
23
24
  - README.textile
24
25
  files:
25
26
  - MIT-LICENSE
27
+ - README
26
28
  - README.textile
27
29
  - Rakefile
28
30
  - VERSION
31
+ - generators/ginsu/USAGE
32
+ - generators/ginsu/ginsu_generator.rb
33
+ - generators/ginsu/templates/config/initializers/ginsu.rb
29
34
  - ginsu.gemspec
30
35
  - init.rb
31
36
  - install.rb
32
37
  - lib/ginsu.rb
38
+ - lib/ginsu/config.rb
39
+ - lib/ginsu/knife.rb
33
40
  - tasks/ginsu_tasks.rake
34
41
  - test/ginsu_test.rb
35
42
  - test/test_helper.rb