k4slide 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,161 @@
1
+ goog.provide('k4.slide.Slide');
2
+
3
+ goog.require('goog.dom.classes');
4
+ goog.require('goog.style');
5
+ goog.require('goog.math.Size');
6
+ goog.require('goog.math.Coordinate');
7
+ goog.require('goog.ui.Component');
8
+ goog.require('logger');
9
+
10
+
11
+ /**
12
+ * @constructor
13
+ * @extends {goog.ui.Component}
14
+ * @param {Element} element Slide element
15
+ * @param {k4.slide.Config} config Config object
16
+ * @param {*} opt_domHelper Dom helper
17
+ */
18
+ k4.slide.Slide = function(element, config, opt_domHelper) {
19
+ goog.base(this, opt_domHelper);
20
+
21
+ /**
22
+ * @type {k4.slide.Config}
23
+ */
24
+ this.config_ = config;
25
+
26
+ // set internal element (this.element_ = element)
27
+ this.setElementInternal(element);
28
+ this.init_();
29
+ }
30
+ goog.inherits(k4.slide.Slide, goog.ui.Component);
31
+
32
+ /**
33
+ * show my slide
34
+ */
35
+ k4.slide.Slide.prototype.init_ = function() {
36
+ var c = this.config_;
37
+ var el = this.getElement();
38
+ // size
39
+ this.setSizeByConfig();
40
+ // position
41
+ this.setPositionByConfig();
42
+ // hide
43
+ goog.style.showElement(el, false);
44
+ };
45
+
46
+ /**
47
+ * slide size
48
+ * @param {goog.math.Size|number} w width
49
+ * @param {number|null|undefined} opt_h height
50
+ *
51
+ */
52
+ k4.slide.Slide.prototype.setSize = function(w, opt_h) {
53
+ goog.style.setSize(this.getElement(), w, opt_h);
54
+ };
55
+
56
+ k4.slide.Slide.prototype.setSizeByConfig = function() {
57
+ var c = this.config_;
58
+ var slideWidth = c.get('slide.width');
59
+ var slideHeight = c.get('slide.height');
60
+ var size = new goog.math.Size(slideWidth, slideHeight);
61
+ this.setSize(size);
62
+ };
63
+
64
+ /**
65
+ * slide position
66
+ * @param {goog.math.Cordinate|number} left left position
67
+ * @param {number|null|undefined} opt_top top position
68
+ *
69
+ */
70
+ k4.slide.Slide.prototype.setPosition = function(left, opt_top) {
71
+ goog.style.setPosition(this.getElement(), left, opt_top);
72
+ };
73
+
74
+ k4.slide.Slide.prototype.setPositionByConfig = function() {
75
+ var c = this.config_;
76
+ var slideTop = c.get('slide.top');
77
+ var slideLeft = c.get('slide.left');
78
+ var pos = new goog.math.Coordinate(slideLeft, slideTop);
79
+ this.setPosition(pos);
80
+ };
81
+
82
+
83
+ /**
84
+ * show my slide
85
+ */
86
+ k4.slide.Slide.prototype.show = function() {
87
+ var el = this.getElement();
88
+ goog.style.showElement(el, true);
89
+ };
90
+
91
+ /**
92
+ * show my slide
93
+ */
94
+ k4.slide.Slide.prototype.hide = function() {
95
+ var el = this.getElement();
96
+ goog.style.showElement(el, false);
97
+ };
98
+
99
+ /**
100
+ * to previous
101
+ */
102
+ k4.slide.Slide.prototype.toPrev = function() {
103
+ var c = this.getConfig();
104
+ this.applyClasses(
105
+ [c.get('slide.class.prev')],
106
+ [c.get('slide.class.current', c.get('slide.class.next'))]
107
+ );
108
+ this.hide();
109
+ };
110
+
111
+ /**
112
+ * to next
113
+ */
114
+ k4.slide.Slide.prototype.toNext = function() {
115
+ var c = this.getConfig();
116
+ this.applyClasses(
117
+ [c.get('slide.class.next')],
118
+ [c.get('slide.class.current'), c.get('slide.class.prev')]
119
+ );
120
+ this.hide();
121
+ };
122
+
123
+ /**
124
+ * to current
125
+ */
126
+ k4.slide.Slide.prototype.toCurrent = function() {
127
+ var c = this.getConfig();
128
+ this.applyClasses(
129
+ [c.get('slide.class.current')],
130
+ [c.get('slide.class.next'), c.get('slide.class.prev')]
131
+ );
132
+ this.show();
133
+ };
134
+
135
+ /**
136
+ * remove and add class
137
+ * @param {array} addClasses Adding css classes
138
+ * @param {array|undefined|null} opt_removeClasses Removing css classes
139
+ */
140
+ k4.slide.Slide.prototype.applyClasses = function(addClasses, opt_removeClasses) {
141
+ var el = this.getElement();
142
+
143
+ if (goog.isArrayLike(addClasses)) {
144
+ goog.array.forEach(addClasses, function(cls, i, arr) {
145
+ goog.dom.classes.add(el, cls);
146
+ }, this);
147
+ }
148
+
149
+ if (goog.isArrayLike(opt_removeClasses)) {
150
+ goog.array.forEach(opt_removeClasses, function(cls, i, arr) {
151
+ goog.dom.classes.remove(el, cls);
152
+ }, this);
153
+ }
154
+ };
155
+
156
+ /**
157
+ * return config instance.
158
+ */
159
+ k4.slide.Slide.prototype.getConfig = function() {
160
+ return this.config_;
161
+ };
@@ -0,0 +1,11 @@
1
+ // base.css
2
+
3
+ body {}
4
+
5
+ div[role="slide"] {
6
+ position: absolute;
7
+ top: 0px;
8
+ left: 0px;
9
+ }
10
+
11
+ @import 'themes/base';
@@ -0,0 +1,4 @@
1
+ // config
2
+
3
+ $font-color: #333;
4
+ $border-color: #666;
@@ -0,0 +1,6 @@
1
+ // mix-in
2
+
3
+ @mixin horizonal-centerize {
4
+ margin-top: 40% * 3 / 4;
5
+ margin-bottom: 5% * 3 / 4;
6
+ }
@@ -0,0 +1,68 @@
1
+ //
2
+
3
+ @import "_mixin.scss";
4
+ @import "_config.scss";
5
+
6
+
7
+ body {
8
+ background-color: #000000;
9
+ color: #FFFFFF;
10
+ * {
11
+ font-size: 18pt;
12
+ color: $font-color;
13
+ }
14
+ }
15
+
16
+ div[role="slide"] {
17
+ padding: 2%;
18
+ box-sizing: border-box;
19
+ background-color: #FFFFFF;
20
+
21
+ $radius: 1%;
22
+ border-radius: $radius;
23
+ -webkit-border-radius: $radius;
24
+ -moz-border-radius: $radius;
25
+
26
+ > h1, h2, h3, h4, h5, ul, ol, li {
27
+ margin: 0px;
28
+ padding: 0px;
29
+ }
30
+
31
+ &[slide-level="1"], &[slide-level="2"] {
32
+ > h1, h2 {
33
+ @include horizonal-centerize;
34
+ margin-top: 40% * 3 / 4;
35
+ margin-bottom: 5% * 3 / 4;
36
+ padding-left: 1%;
37
+ font-size: 140%;
38
+ }
39
+ > h1 {
40
+ border-bottom: 1px solid $border-color;
41
+ border-left: 10px solid $border-color;
42
+ }
43
+ > h2 {
44
+ border-left: 10px solid $border-color;
45
+ }
46
+ > ul, ol {
47
+ text-align: right;
48
+ list-style-type: none;
49
+ }
50
+ }
51
+
52
+ &[slide-level="3"] {
53
+ > h3 {
54
+ border-bottom: 1px solid $border-color;
55
+ font-size: 120%;
56
+ }
57
+ }
58
+
59
+ &:last-child {
60
+ > h3 {
61
+ display: none;
62
+ }
63
+ > p {
64
+ @include horizonal-centerize;
65
+ text-align: center;
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,43 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4
+ <title>example</title>
5
+ <link rel="stylesheet" type="text/css" href="../assets/k4slide.css">
6
+ </head>
7
+ <body>
8
+
9
+ <div role="slide" page="1" slide-level="1">
10
+ <h1>Markdown 2 Slide</h1>
11
+
12
+ <ul>
13
+ <li>Shinichirow KAMITO</li>
14
+ </ul>
15
+ </div>
16
+
17
+ <div role="slide" page="2" slide-level="2">
18
+ <h2>What?</h2>
19
+
20
+ <p>What is this?</p>
21
+ </div>
22
+
23
+ <div role="slide" page="3" slide-level="3">
24
+ <h3>What is Markdown?</h3>
25
+
26
+ <p>Markdown is a lightweight markup language.</p>
27
+ </div>
28
+
29
+ <div role="slide" page="4" slide-level="2">
30
+ <h2>Why?</h2>
31
+
32
+ <p>Why</p>
33
+ </div>
34
+
35
+ <div role="slide" page="5" slide-level="3">
36
+ <h3>Thank you for listen.</h3>
37
+
38
+ <p>Thank you for listen.</p>
39
+
40
+
41
+ <script type="text/javascript" src="../assets/k4slide.js"></script>
42
+ </body>
43
+ </html>
@@ -0,0 +1,19 @@
1
+ # Markdown 2 Slide #
2
+
3
+ * Shinichirow KAMITO
4
+
5
+ ## What? ##
6
+
7
+ What is this?
8
+
9
+ ### What is Markdown? ###
10
+
11
+ Markdown is a lightweight markup language.
12
+
13
+ ## Why? ##
14
+
15
+ Why
16
+
17
+ ### Thank you for listen. ###
18
+
19
+ Thank you for listen.
data/k4slide.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'k4slide/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "k4slide"
8
+ spec.version = K4slide::VERSION
9
+ spec.authors = ["Shinichirow Kamito"]
10
+ spec.email = ["kamito@i3-systems.com"]
11
+ spec.description = "k4 slide"
12
+ spec.summary = "k4 slide"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "k4compiler", "= 0.0.1"
22
+ spec.add_dependency "rake"
23
+ spec.add_dependency "activesupport", "~> 3.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "guard-rspec"
28
+ end
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4
+ <title><%= @title %></title>
5
+ <link rel="stylesheet" type="text/css" href="../assets/k4slide.css">
6
+ </head>
7
+ <body>
8
+
9
+ <%= @body %>
10
+
11
+ <script type="text/javascript" src="../assets/k4slide.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,50 @@
1
+ require 'active_support/core_ext/hash'
2
+
3
+ module K4compiler
4
+
5
+ class Closure
6
+ class << self
7
+ def expand_options
8
+ opt = {
9
+ :target_dir => nil,
10
+ :compiled_dir => nil,
11
+ :with_closure => true,
12
+ :namespace_suffix => 'App',
13
+ }
14
+ return original_options.update(opt).with_indifferent_access()
15
+ end
16
+ alias :original_options :options
17
+ alias :options :expand_options
18
+ end
19
+ end
20
+
21
+ class Scss
22
+ class << self
23
+ def expand_options
24
+ opt = {
25
+ :target_dir => nil,
26
+ :compiled_dir => nil,
27
+ :ext => 'scss',
28
+ }
29
+ return original_options.update(opt).with_indifferent_access()
30
+ end
31
+ alias :original_options :options
32
+ alias :options :expand_options
33
+ end
34
+ end
35
+
36
+ class Markdown
37
+ class << self
38
+ def expand_options
39
+ opt = {
40
+ :target_dir => nil,
41
+ :compiled_dir => nil,
42
+ :renderer => ::K4slide::MarkdownRenderer,
43
+ }
44
+ return original_options.update(opt).with_indifferent_access()
45
+ end
46
+ alias :original_options :options
47
+ alias :options :expand_options
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ require 'erb'
2
+
3
+ module K4slide
4
+ class MarkdownCompiler
5
+
6
+ def initialize(compiler)
7
+ @compiler = compiler
8
+ end
9
+
10
+ def to_slide(md_src)
11
+ @body = @compiler.markdown.compile(md_src)
12
+ @title = 'example'
13
+
14
+ layout_src = read_layout_template()
15
+ erb = ERB.new(layout_src)
16
+ source = erb.result(binding)
17
+ return source
18
+ end
19
+
20
+ def read_layout_template
21
+ layout_dir = File.expand_path(File.join(File.dirname(__FILE__), 'erb'))
22
+ layout_template = File.join(layout_dir, 'layout.html.erb')
23
+ src = File.read(layout_template)
24
+ return src
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ module K4slide
2
+ class MarkdownRenderer < ::K4compiler::MarkdownRenderer
3
+
4
+ attr_accessor :config
5
+
6
+ def initialize(*args)
7
+ super(*args)
8
+ @started_ = false
9
+ @level_ = 0
10
+ @page_ = 0
11
+ @current_ = nil
12
+ end
13
+
14
+ def header(text, header_level)
15
+ @page_ += 1
16
+ @level_ = header_level
17
+
18
+ html = ""
19
+ html << "</div>\n\n" if @started_
20
+ html << <<__HEAD__
21
+ <div role="slide" page="#{@page_}" slide-level="#{header_level}">
22
+ <h#{header_level}>#{text}</h#{header_level}>
23
+ __HEAD__
24
+ @current_ = html
25
+ @started_ = true
26
+ return html
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,158 @@
1
+
2
+ require 'rake/clean'
3
+ require 'k4compiler'
4
+ require 'k4slide/expand_compiler_options'
5
+
6
+ module K4slide
7
+
8
+ module Tasks
9
+ def self.install(&block)
10
+ instance = K4slideTasks.new
11
+ instance.install(&block)
12
+ end
13
+
14
+ class K4slideTasks
15
+ include Rake::DSL
16
+
17
+ def initialize
18
+ @compiler = nil
19
+ end
20
+
21
+ def install(&block)
22
+ @compiler = ::K4compiler.setup(&block)
23
+ @config = @compiler.config
24
+
25
+ namespace :k4s do
26
+ namespace :compile do
27
+ desc 'Compile JavaScript source with Closure Library.'
28
+ task :closure => get_closure_sources()
29
+
30
+ desc 'Compile SASS sources'
31
+ task :sass => get_sass_source()
32
+
33
+ desc 'Compile Markdown sources'
34
+ task :markdown do
35
+ puts "Compile Markdown"
36
+ end
37
+
38
+ desc 'Compile sources.'
39
+ task :all => ['k4s:compile:closure', 'k4s:compile:sass', 'k4s:compile:markdown']
40
+ end
41
+
42
+ namespace :example do
43
+ task :md2s => (['k4s:example:compile'] + example_markdown_targets())
44
+ task :compile => ['k4s:compile:all']
45
+ end
46
+ end
47
+ end
48
+
49
+ # @return [FileList]
50
+ def get_closure_sources
51
+ target_files = []
52
+ source_dir = @config.closure.target_dir
53
+ compiled_dir = @config.closure.compiled_dir
54
+
55
+ depends_files = []
56
+ @config.closure.load_paths << source_dir
57
+ @config.closure.load_paths.each do |load_path|
58
+ depends_files += FileList[File.join(load_path, '**/*.js')].flatten if load_path
59
+ end
60
+
61
+ ns_suffix = @config.closure.namespace_suffix || 'App'
62
+
63
+ filelist = FileList[File.join(source_dir, '*.js')]
64
+ filelist.each do |source_path|
65
+ source_basename = File.basename(source_path)
66
+ target_path = File.join(compiled_dir, source_basename)
67
+ same_name_dir = source_path.gsub(/\.js$/, '')
68
+ depends = depends_files.dup
69
+ depends.unshift(FileList[File.join(same_name_dir, '**/*.js')].flatten)
70
+ depends.unshift(source_path)
71
+ depends = depends.flatten
72
+
73
+ file(target_path => depends) do |t, args|
74
+ basename = File.basename(t.name).gsub(/\.js$/, '')
75
+ namespace = "#{basename}.#{ns_suffix}"
76
+ js_source = @compiler.closure.compile(namespace)
77
+ File.open(target_path, 'w') do |io|
78
+ io.write(js_source)
79
+ end
80
+ end
81
+
82
+ target_files << target_path
83
+ end
84
+
85
+ return target_files
86
+ end
87
+
88
+ # @return [FileList]
89
+ def get_sass_source()
90
+ target_files = []
91
+ source_dir = @config.scss.target_dir
92
+ compiled_dir = @config.scss.compiled_dir
93
+ ext = @config.scss.ext || 'scss'
94
+
95
+ @config.scss.load_paths << source_dir
96
+
97
+ depends_files = []
98
+ @config.scss.load_paths.each do |load_path|
99
+ depends_files += FileList[File.join(load_path, "**/*.#{ext}")].flatten if load_path
100
+ end
101
+
102
+ filelist = FileList[File.join(source_dir, "*.#{ext}")]
103
+ filelist.each do |source_path|
104
+ source_basename = File.basename(source_path)
105
+ next if source_basename =~ /^_/
106
+
107
+ source_basename = source_basename.gsub(/#{ext}$/, 'css')
108
+ target_path = File.join(compiled_dir, source_basename)
109
+ depends = depends_files.dup
110
+ depends.unshift(source_path)
111
+
112
+ file(target_path => depends) do |t, args|
113
+ puts t.name
114
+ src = File.read(source_path)
115
+ css_source = @compiler.scss.compile(src)
116
+ File.open(target_path, 'w') do |io|
117
+ io.write(css_source)
118
+ end
119
+ end
120
+
121
+ target_files << target_path
122
+ end
123
+
124
+ return target_files
125
+ end
126
+
127
+ # Compiling example markdown file
128
+ def example_markdown_targets()
129
+ target_files = []
130
+
131
+ example_dir = File.join(K4_ROOT, 'example')
132
+ ext = 'md'
133
+ filelist = FileList[File.join(example_dir, "*.#{ext}")]
134
+ puts filelist
135
+
136
+ filelist.each do |source_path|
137
+ source_basename = File.basename(source_path)
138
+ next if source_basename =~ /^_/
139
+
140
+ source_basename = source_basename.gsub(/#{ext}$/, 'html')
141
+ target_path = File.join(example_dir, source_basename)
142
+
143
+ file(target_path) do |t, args|
144
+ puts t.name
145
+ src = File.read(source_path)
146
+ compiler_ = MarkdownCompiler.new(@compiler)
147
+ html_source = compiler_.to_slide(src)
148
+ File.open(target_path, 'w') do |io|
149
+ io.write(html_source)
150
+ end
151
+ end
152
+ target_files << target_path
153
+ end
154
+ return target_files
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,3 @@
1
+ module K4slide
2
+ VERSION = "0.0.1"
3
+ end
data/lib/k4slide.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "k4slide/version"
2
+ require 'active_support'
3
+
4
+ module K4slide
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :MarkdownCompiler
8
+ autoload :MarkdownRenderer
9
+ autoload :Tasks
10
+ end