bastos-gary 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{gary}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Tiago Bastos"]
9
+ s.date = %q{2008-11-12}
10
+ s.default_executable = %q{gary}
11
+ s.description = %q{A Web Presentation Creator with Markaby}
12
+ s.email = %q{comechao@gmail.com}
13
+ s.executables = ["gary"]
14
+ s.extra_rdoc_files = ["bin/gary", "lib/gary.rb", "lib/albino.rb", "README.rdoc"]
15
+ s.files = ["bin/gary", "lib/gary.rb", "lib/albino.rb", "Manifest", "Rakefile", "assets/style.css", "assets/outline.css", "assets/gary.js", "assets/slides.css", "assets/jquery.js", "assets/slides.js", "assets/print.css", "README.rdoc", "examples/test.rb", "gary.gemspec"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://github.com/bastos/gary}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Gary", "--main", "README.rdoc"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{gary}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{A Web Presentation Creator with Markaby}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_development_dependency(%q<markaby>, [">= 0"])
30
+ s.add_development_dependency(%q<open4>, [">= 0"])
31
+ else
32
+ s.add_dependency(%q<markaby>, [">= 0"])
33
+ s.add_dependency(%q<open4>, [">= 0"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<markaby>, [">= 0"])
37
+ s.add_dependency(%q<open4>, [">= 0"])
38
+ end
39
+ end
@@ -0,0 +1,116 @@
1
+ ##
2
+ # Wrapper for the Pygments command line tool, pygmentize.
3
+ #
4
+ # Pygments: http://pygments.org/
5
+ #
6
+ # Assumes pygmentize is in the path. If not, set its location
7
+ # with Albino.bin = '/path/to/pygmentize'
8
+ #
9
+ # Use like so:
10
+ #
11
+ # @syntaxer = Albino.new('/some/file.rb', :ruby)
12
+ # puts @syntaxer.colorize
13
+ #
14
+ # This'll print out an HTMLized, Ruby-highlighted version
15
+ # of '/some/file.rb'.
16
+ #
17
+ # To use another formatter, pass it as the third argument:
18
+ #
19
+ # @syntaxer = Albino.new('/some/file.rb', :ruby, :bbcode)
20
+ # puts @syntaxer.colorize
21
+ #
22
+ # You can also use the #colorize class method:
23
+ #
24
+ # puts Albino.colorize('/some/file.rb', :ruby)
25
+ #
26
+ # Another also: you get a #to_s, for somewhat nicer use in Rails views.
27
+ #
28
+ # ... helper file ...
29
+ # def highlight(text)
30
+ # Albino.new(text, :ruby)
31
+ # end
32
+ #
33
+ # ... view file ...
34
+ # <%= highlight text %>
35
+ #
36
+ # The default lexer is 'text'. You need to specify a lexer yourself;
37
+ # because we are using STDIN there is no auto-detect.
38
+ #
39
+ # To see all lexers and formatters available, run `pygmentize -L`.
40
+ #
41
+ # Chris Wanstrath // chris@ozmm.org
42
+ # GitHub // http://github.com
43
+ #
44
+ require 'open4'
45
+
46
+ class Albino
47
+ @@bin = 'pygmentize'
48
+
49
+ def self.bin=(path)
50
+ @@bin = path
51
+ end
52
+
53
+ def self.colorize(*args)
54
+ new(*args).colorize
55
+ end
56
+
57
+ def initialize(target, lexer = :text, format = :html)
58
+ @target = File.exists?(target) ? File.read(target) : target rescue target
59
+ @options = { :l => lexer, :f => format }
60
+ end
61
+
62
+ def execute(command)
63
+ pid, stdin, stdout, stderr = Open4.popen4(command)
64
+ stdin.puts @target
65
+ stdin.close
66
+ stdout.read.strip
67
+ end
68
+
69
+ def colorize(options = {})
70
+ execute @@bin + convert_options(options)
71
+ end
72
+ alias_method :to_s, :colorize
73
+
74
+ def convert_options(options = {})
75
+ @options.merge(options).inject('') do |string, (flag, value)|
76
+ string + " -#{flag} #{value}"
77
+ end
78
+ end
79
+ end
80
+
81
+ if $0 == __FILE__
82
+ require 'rubygems'
83
+ require 'test/spec'
84
+ require 'mocha'
85
+ begin require 'redgreen'; rescue LoadError; end
86
+
87
+ context "Albino" do
88
+ setup do
89
+ @syntaxer = Albino.new(__FILE__, :ruby)
90
+ end
91
+
92
+ specify "defaults to text" do
93
+ syntaxer = Albino.new(__FILE__)
94
+ syntaxer.expects(:execute).with('pygmentize -f html -l text').returns(true)
95
+ syntaxer.colorize
96
+ end
97
+
98
+ specify "accepts options" do
99
+ @syntaxer.expects(:execute).with('pygmentize -f html -l ruby').returns(true)
100
+ @syntaxer.colorize
101
+ end
102
+
103
+ specify "works with strings" do
104
+ syntaxer = Albino.new('class New; end', :ruby)
105
+ assert_match %r(highlight), syntaxer.colorize
106
+ end
107
+
108
+ specify "aliases to_s" do
109
+ assert_equal @syntaxer.colorize, @syntaxer.to_s
110
+ end
111
+
112
+ specify "class method colorize" do
113
+ assert_equal @syntaxer.colorize, Albino.colorize(__FILE__, :ruby)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,139 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $:.unshift File.expand_path(File.dirname(__FILE__))
4
+
5
+ require 'rubygems'
6
+ require 'markaby'
7
+ require 'fileutils'
8
+ require 'ftools'
9
+ require 'albino'
10
+
11
+ # Gary Presentation Builder
12
+ # JS and part of the CSS from http://slideshow.rubyforge.org/
13
+ module Gary
14
+
15
+ #Main method to parse the ARGV.
16
+ def self.main(args)
17
+ if not args[0]
18
+ self.usage
19
+ elsif args[0] == '--assets'
20
+ self.create_assets
21
+ else args[0] == '--render' or args[0] == '-r'
22
+ self.generate(args[1])
23
+ end
24
+ end
25
+
26
+ # Generate the presentation from a presentation file source.
27
+ def self.generate(presentation_source)
28
+ raise "File #{presentation_source} don't exists!" unless File.exists?(presentation_source)
29
+ f = File.expand_path "#{presentation_source}"
30
+ puts "Creating presentation: #{f}"
31
+ p = Gary::Builder.new
32
+ presentation_file = f.gsub(/\.rb$/, '')
33
+ out = File.new( "#{presentation_file}.html", "w+" )
34
+ out << p.instance_eval(File.new(f).read, f)
35
+ out.flush
36
+ out.close
37
+ end
38
+
39
+ # Create the assets directory with the standards files.
40
+ # To use your custom theme just modify the assets/style.css generated by this method.
41
+ # To restore just remove the style file and run --assets again.
42
+ def self.create_assets
43
+ Dir.mkdir( 'assets' ) unless File.directory?( 'assets' )
44
+
45
+ source = File.expand_path "#{File.dirname(__FILE__)}/../assets/"
46
+ dest = "./assets/"
47
+
48
+ puts "Copying '#{source} ' to '#{dest}'"
49
+
50
+ Dir.glob(source+"/*.*").each do |f|
51
+ if not File.exists?(File.expand_path(dest+ File.basename(f)))
52
+ puts "Copying #{f}"
53
+ FileUtils.cp(File.expand_path(f), dest)
54
+ else
55
+ puts "Skipped #{f}"
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ # Print usage message.
62
+ def self.usage
63
+ puts "Hello! To render the slide show just type gary.
64
+ To add the assets folder just type, gary --assets.
65
+ BYE"
66
+ puts Albino.new('class New; end', :ruby).colorize
67
+ puts "woot"
68
+ end
69
+
70
+ # Build de presentation slides.
71
+ class Builder < Markaby::Builder
72
+ attr_reader :presentation_options
73
+
74
+ # Render the slideshow HTML.
75
+ def render
76
+ to_s
77
+ end
78
+
79
+ 1 # Create a presentation with all slides, headers, controls etc.
80
+ # You must pass the presentation title.
81
+ def presentation(options = {}, &block)
82
+ raise "Must have a title" unless options.has_key? :title
83
+
84
+ @presentation_options = options
85
+ html do
86
+ head do
87
+ meta :name=>"defaultView", :content=>"slideshow"
88
+ link.outlineStyle! :rel => 'stylesheet', :type => 'text/css',
89
+ :href => 'assets/outline.css', :media => 'screen'
90
+ link.slideStyle! :rel => 'stylesheet', :type => 'text/css',
91
+ :href => '/print.css', :media => 'print'
92
+ link.slideProj! :rel => 'stylesheet', :type => 'text/css',
93
+ :href => 'assets/style.css', :media => 'projection'
94
+ link :rel => 'stylesheet', :type => 'text/css',
95
+ :href => 'assets/prettify.css', :media => 'screen'
96
+
97
+ script :src => "assets/jquery.js", :type => "text/javascript"
98
+ script :src => "assets/slides.js", :type => "text/javascript"
99
+ script :src => "assets/gary.js", :type => "text/javascript"
100
+
101
+ title @presentation_options[:title]
102
+ end
103
+ body do
104
+
105
+ div.layout! do
106
+ div.controls! { }
107
+ div.currentSlide! { }
108
+ div.header! { }
109
+ div.footer! do
110
+ h1 @presentation_options[:title]
111
+ end
112
+ div.microsoft! do
113
+ self << "Microsoft's Internet Explorer browser
114
+ has no built-in vector graphics machinery
115
+ required for \"loss-free\" gradient background themes."
116
+ end
117
+ end
118
+
119
+ div.presentation do
120
+ instance_eval(&block)
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ # Create a slide, you can pass some options, same options accepted by "div" tag.
127
+ def slide(options = {}, &block)
128
+ div.slide options do
129
+ div.container { instance_eval(&block) }
130
+ end
131
+ end
132
+
133
+ # Generates synta hightlight for code using albino
134
+ def code(options = {})
135
+ self << Albino.new(options[:code], options[:type]).colorize
136
+ end
137
+
138
+ end
139
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bastos-gary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tiago Bastos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-12 00:00:00 -08:00
13
+ default_executable: gary
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: markaby
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: open4
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: A Web Presentation Creator with Markaby
34
+ email: comechao@gmail.com
35
+ executables:
36
+ - gary
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - bin/gary
41
+ - lib/gary.rb
42
+ - lib/albino.rb
43
+ - README.rdoc
44
+ files:
45
+ - bin/gary
46
+ - lib/gary.rb
47
+ - lib/albino.rb
48
+ - Manifest
49
+ - Rakefile
50
+ - assets/style.css
51
+ - assets/outline.css
52
+ - assets/gary.js
53
+ - assets/slides.css
54
+ - assets/jquery.js
55
+ - assets/slides.js
56
+ - assets/print.css
57
+ - README.rdoc
58
+ - examples/test.rb
59
+ - gary.gemspec
60
+ has_rdoc: true
61
+ homepage: http://github.com/bastos/gary
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --line-numbers
65
+ - --inline-source
66
+ - --title
67
+ - Gary
68
+ - --main
69
+ - README.rdoc
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "1.2"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: gary
87
+ rubygems_version: 1.2.0
88
+ signing_key:
89
+ specification_version: 2
90
+ summary: A Web Presentation Creator with Markaby
91
+ test_files: []
92
+