coyote 0.5.2 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/Manifest +40 -2
  2. data/bin/coyote +16 -4
  3. data/coyote.gemspec +10 -9
  4. data/lib/coyote.rb +25 -34
  5. data/lib/coyote/configuration.rb +57 -61
  6. data/lib/coyote/generator.rb +35 -35
  7. data/lib/coyote/script.rb +122 -0
  8. data/lib/coyote/scripts/coffeescript.rb +32 -0
  9. data/lib/coyote/scripts/combine.rb +54 -0
  10. data/lib/coyote/scripts/javascript.rb +4 -0
  11. data/test/assets/javascripts/app/confio.coffee +2 -0
  12. data/test/assets/javascripts/app/confio/interface.coffee +8 -0
  13. data/test/assets/javascripts/app/confio/main.coffee +4 -0
  14. data/test/assets/javascripts/lib/keystone/extensions.coffee +8 -0
  15. data/test/assets/javascripts/lib/keystone/forms.coffee +19 -0
  16. data/test/assets/javascripts/lib/keystone/utilities.coffee +2 -0
  17. data/test/assets/stylesheets/app/_confio.scss +4 -0
  18. data/test/assets/stylesheets/app/confio/_ie.scss +39 -0
  19. data/test/assets/stylesheets/app/confio/_mobile.scss +28 -0
  20. data/test/assets/stylesheets/app/confio/_print.scss +129 -0
  21. data/test/assets/stylesheets/app/confio/_screen.scss +624 -0
  22. data/test/assets/stylesheets/lib/_keystone.scss +4 -0
  23. data/test/assets/stylesheets/lib/keystone/_css3.scss +6 -0
  24. data/test/assets/stylesheets/lib/keystone/_scaffolding.scss +2 -0
  25. data/test/assets/stylesheets/lib/keystone/_typography.scss +3 -0
  26. data/test/assets/stylesheets/lib/keystone/_utilities.scss +3 -0
  27. data/test/assets/stylesheets/lib/keystone/css3/_background-clip.scss +5 -0
  28. data/test/assets/stylesheets/lib/keystone/css3/_border-radius.scss +5 -0
  29. data/test/assets/stylesheets/lib/keystone/css3/_box-shadow.scss +5 -0
  30. data/test/assets/stylesheets/lib/keystone/css3/_box-sizing.scss +5 -0
  31. data/test/assets/stylesheets/lib/keystone/css3/_opacity.scss +6 -0
  32. data/test/assets/stylesheets/lib/keystone/css3/_transition.scss +5 -0
  33. data/test/assets/stylesheets/lib/keystone/scaffolding/_reset.scss +75 -0
  34. data/test/assets/stylesheets/lib/keystone/scaffolding/_structure.scss +23 -0
  35. data/test/assets/stylesheets/lib/keystone/typography/_links.scss +66 -0
  36. data/test/assets/stylesheets/lib/keystone/typography/_lists.scss +38 -0
  37. data/test/assets/stylesheets/lib/keystone/typography/_replacement.scss +12 -0
  38. data/test/assets/stylesheets/lib/keystone/utilities/_alignment.scss +3 -0
  39. data/test/assets/stylesheets/lib/keystone/utilities/_autoclear.scss +11 -0
  40. data/test/assets/stylesheets/lib/keystone/utilities/_hoverbox.scss +32 -0
  41. data/test/assets/stylesheets/styles.scss +58 -0
  42. data/test/assets/stylesheets/vendor/_vendor.scss +0 -0
  43. data/test/public/scripts/coyote.js +93 -0
  44. data/test/public/scripts/jquery.js +4 -0
  45. data/test/public/scripts/scripts.combine +6 -0
  46. data/test/public/scripts/scripts.js +91 -0
  47. metadata +61 -19
  48. data/lib/coyote/coy_file.rb +0 -64
  49. data/lib/coyote/output.rb +0 -72
@@ -0,0 +1,122 @@
1
+ module Coyote
2
+ autoload :JavaScript, 'coyote/scripts/javascript'
3
+ autoload :CoffeeScript, 'coyote/scripts/coffeescript'
4
+ autoload :Combine, 'coyote/scripts/combine'
5
+
6
+ class Script
7
+ attr_accessor :filename, :contents
8
+
9
+ # Class method
10
+ # Determine the type of file base on the file extension
11
+ # and return an instance of the proper extended script class
12
+ def self.select_and_init(filename)
13
+ case File.extname(filename)
14
+ when /\.js/i ; JavaScript.new(filename)
15
+ when /\.coffee/i ; CoffeeScript.new(filename)
16
+ when /\.combine/i ; Combine.new(filename)
17
+ else ; self.new(filename)
18
+ end
19
+ end
20
+
21
+
22
+ def initialize(filename, contents = "")
23
+ @filename = filename
24
+ @directory = File.dirname(@filename)
25
+
26
+ if contents.empty? and File.exists? @filename
27
+ @contents = File.open(@filename, 'r').read
28
+ else
29
+ @contents = contents
30
+ end
31
+ end
32
+
33
+
34
+ # Append a string of additional content
35
+ # to the end of the current script contents
36
+ def append(string)
37
+ @contents += "#{string}\n\n"
38
+ end
39
+
40
+
41
+ # Prepend a string of additional content
42
+ # to the beginning of the current script contents
43
+ def prepend(string)
44
+ @contents = "#{string}\n\n" + @contents
45
+ end
46
+
47
+
48
+ # Defines the regex pattern for scanning the contents of the
49
+ # file to look for require directives
50
+ def require_pattern
51
+ Regexp.new(/\/\/=\s*require\s*(.*)$/i) # '//= require a/b/c.js' => 'a/b/c.js'
52
+ end
53
+
54
+
55
+ # Scan the contents of the file for require directives
56
+ # By default, it looks for a directive of '//= require a/b/c.js'
57
+ # It determines the full filepath of the required file,
58
+ # relative to the current file being read in
59
+ def requires(pattern = require_pattern)
60
+ matches = @contents.scan(pattern)
61
+ matches.collect do |match|
62
+ File.expand_path(match.last.strip, @directory)
63
+ end
64
+ end
65
+
66
+
67
+ # Clear out the contents of the script, in-place
68
+ def empty!
69
+ @contents = ""
70
+ end
71
+
72
+
73
+ # Run the contents of the script through the Google Closure compile
74
+ # It compresses the contents of the script in-place
75
+ def compress!
76
+ Coyote::Notification.new "Compiling #{@filename}...\n", "warning"
77
+ compiler = ClosureCompiler.new.compile(@contents)
78
+ if compiler.success?
79
+ @contents = compiler.compiled_code
80
+ elsif compiler.file_too_big?
81
+ Coyote::Notification.new "Input code too big for API, creating uncompiled file\n", "failure"
82
+ elsif compiler.errors
83
+ Coyote::Notification.new "Google closure API failed to compile, creating uncompiled file\n", "failure"
84
+ Coyote::Notification.new "Errors: \n", "failure"
85
+ Coyote::Notification.new "#{compiler.errors.to_s}\n\n", "failure"
86
+ end
87
+ end
88
+
89
+
90
+ # Save the contents of the script to disk
91
+ def save
92
+ output = File.open @filename, 'w+'
93
+ output.write @contents
94
+ output.close
95
+ end
96
+
97
+
98
+
99
+ protected
100
+
101
+ # This method converts a JavaScript filepath to a CoffeeScript filepath in the same directory
102
+ # Given the path /a/b/c.js it will return /a/b/c.coffee
103
+ def convert_js_path_to_coffee(path)
104
+ directory, basename = File.split(path)
105
+ basename = File.basename(basename, '.js')
106
+ "#{directory}/#{basename}.coffee"
107
+ end
108
+
109
+ # This method converts a CoffeeScript filepath to a JavaScript filepath in the same directory
110
+ # Given the path /a/b/c.coffee it will return /a/b/c.js
111
+ def convert_coffee_path_to_js(path)
112
+ directory, basename = File.split(path)
113
+ basename = File.basename(basename, '.coffee')
114
+ "#{directory}/#{basename}.js"
115
+ end
116
+
117
+
118
+
119
+ end
120
+ end
121
+
122
+
@@ -0,0 +1,32 @@
1
+ module Coyote
2
+ class CoffeeScript < Script
3
+
4
+ # Defines the regex pattern for scanning the contents of the
5
+ # file to look for require directives
6
+ def require_pattern
7
+ Regexp.new(/#=\s*require\s(.*)$/i) # '#= require a/b/c.coffee' => 'a/b/c.coffee'
8
+ end
9
+
10
+
11
+ # We're defining setters and getters here
12
+ # for the contents of the script file
13
+ # because we need to compile the CoffeeScript to JavaScript
14
+ # on the way out
15
+ def contents=(string)
16
+ @contents = string
17
+ end
18
+
19
+ def contents
20
+ compile!
21
+ @contents
22
+ end
23
+
24
+
25
+ # Run the contents of the script through the CoffeeScript compile
26
+ # Changes the content of the script in-place
27
+ def compile!
28
+ @contents = `cat #{@filename} | coffee -sc`
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,54 @@
1
+ module Coyote
2
+
3
+ # This class adds support for .combine files, following the style
4
+ # of SassAndCoffee for .NET (https://github.com/xpaulbettsx/SassAndCoffee)
5
+
6
+ class Combine < Script
7
+
8
+ # .combine files serve primarily as a manifest listing files to pull in and combine
9
+ # In turn, each line of a .combine file is a require directive, so what we do here
10
+ # to detemine requires is read in each line of the file, do a bit of cleanup,
11
+ # and return an array of full filepaths of the required files
12
+ def requires
13
+ requires = []
14
+
15
+ File.open(@filename).readlines.each do |line|
16
+ # Because the directives in the .combine file are not comments,
17
+ # we have to strip out the directives from the file's contents
18
+ @contents.gsub!(/#{line}/, '')
19
+
20
+ # Clean up whitespace on the directive, and make sure it's not a blank line
21
+ if line.strip! != ''
22
+
23
+ # The .NET .combine engine automatically detects .js files as their .coffee counterparts
24
+ # so we need to replicate that functionality and also look for .coffee files with the same filename
25
+ file = check_for_alternate_filetype(File.expand_path(line, @directory))
26
+ if file
27
+ requires << file
28
+ end
29
+ end
30
+ end
31
+
32
+ return requires
33
+ end
34
+
35
+
36
+ # This method with look for an alternate filetype for a given filepath
37
+ # If it is given a path of /a/b/c.js it will look for /a/b/c.coffee
38
+ # and return whichever filetype it finds first
39
+ # It looks for JavaScript first and then CoffeeScript, returning nil if it doesn't find anything
40
+ def check_for_alternate_filetype(path)
41
+ javascript = path
42
+ coffeescript = convert_js_path_to_coffee(javascript)
43
+
44
+ if File.file?(javascript)
45
+ javascript
46
+ elsif File.file?(coffeescript)
47
+ coffeescript
48
+ else
49
+ nil
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ module Coyote
2
+ class JavaScript < Script
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ $ ->
2
+ ClientName.main()
@@ -0,0 +1,8 @@
1
+ @module "ClientName", ->
2
+
3
+ class @Interface
4
+ constructor: ->
5
+ do @build
6
+
7
+ build: ->
8
+ new Keystone.Forms
@@ -0,0 +1,4 @@
1
+ @module "ClientName", ->
2
+
3
+ @main = ->
4
+ @interface = new ClientName.Interface
@@ -0,0 +1,8 @@
1
+ @module = (names, fn) ->
2
+ names = names.split '.' if typeof names is 'string'
3
+ space = @[names.shift()] ||= {}
4
+ space.module ||= @module
5
+ if names.length
6
+ space.module names, fn
7
+ else
8
+ fn.call space
@@ -0,0 +1,19 @@
1
+ @module "Keystone", ->
2
+ class @Forms
3
+
4
+ constructor: ($form) ->
5
+ do @build
6
+
7
+ build: ->
8
+ if not Keystone.elementSupportsAttribute 'input', 'placeholder'
9
+ $('input[placeholder]').each ->
10
+ $input = $(this)
11
+ placeholder = $input.attr 'placeholder'
12
+ $input.val(placeholder).addClass 'inactive'
13
+ $input.bind
14
+ focus : ->
15
+ if $input.val() is placeholder
16
+ $input.val('').removeClass 'inactive'
17
+ blur : ->
18
+ if $input.val() is ''
19
+ $input.val(placeholder).addClass 'inactive'
@@ -0,0 +1,2 @@
1
+ Keystone.elementSupportsAttribute = (element, attribute)->
2
+ attribute of document.createElement element
@@ -0,0 +1,4 @@
1
+ @import "confio/screen";
2
+ @import "confio/mobile";
3
+ @import "confio/ie";
4
+ @import "confio/print";
@@ -0,0 +1,39 @@
1
+ /* =IE Fixes
2
+ ---------------------------------------------------------------------------- */
3
+
4
+ .ie {
5
+ #main fieldset.pulled p {
6
+ zoom: 1; // Fixes and IE bug that causes text to jump that has a negative margin
7
+ }
8
+ }
9
+
10
+
11
+ /* =IE6 Fixes
12
+ ---------------------------------------------------------------------------- */
13
+
14
+ .ie6 {
15
+
16
+ }
17
+
18
+
19
+ /* =IE7 Fixes
20
+ ---------------------------------------------------------------------------- */
21
+
22
+ .ie7 {
23
+
24
+ }
25
+
26
+
27
+ /* =IE8 Fixes
28
+ ---------------------------------------------------------------------------- */
29
+
30
+ .ie8 {
31
+
32
+ }
33
+
34
+
35
+ /* =IE9 Fixes
36
+ ---------------------------------------------------------------------------- */
37
+ .ie9 {
38
+
39
+ }
@@ -0,0 +1,28 @@
1
+ /* =Tablet (Portrait) - Design for a width of 768px
2
+ ---------------------------------------------------------------------------- */
3
+
4
+ @media only screen and (min-width: 768px) and (max-width: 959px) {
5
+ .container {
6
+ width: 768px;
7
+ }
8
+ }
9
+
10
+
11
+ /* =Mobile (Portrait) - Design for a width of 320px
12
+ ---------------------------------------------------------------------------- */
13
+
14
+ @media only screen and (max-width: 767px) {
15
+ .container {
16
+ width: 300px;
17
+ }
18
+ }
19
+
20
+
21
+ /* =Mobile (Landscape) - Design for a width of 480px
22
+ ---------------------------------------------------------------------------- */
23
+
24
+ @media only screen and (min-width: 480px) and (max-width: 767px) {
25
+ .container {
26
+ width: 420px;
27
+ }
28
+ }
@@ -0,0 +1,129 @@
1
+ /* =Print
2
+ ---------------------------------------------------------------------------- */
3
+
4
+ @media print {
5
+ body {
6
+ font: 10pt/1.5 Georgia, "Times New Roman", Times, serif;
7
+ color: #000;
8
+ width: 100%;
9
+ margin: 0;
10
+ padding: 0;
11
+ }
12
+
13
+ #nav,
14
+ #search,
15
+ #sidebar,
16
+ #footer ul {
17
+ display: none;
18
+ }
19
+
20
+ h1, h2, h3, h4, h5, h6 {
21
+ font-family: Helvetica, Arial, sans-serif;
22
+ font-weight: normal;
23
+ }
24
+
25
+ h1 {
26
+ font-size: 20pt;
27
+ color: #55251F;
28
+ }
29
+
30
+ h2 {
31
+ font-size: 18pt;
32
+ color: #35551C;
33
+ }
34
+
35
+ h3 {
36
+ font-size: 16pt;
37
+ color: #184C99;
38
+ }
39
+
40
+ h4 {
41
+ font-size: 14pt;
42
+ font-weight: 700;
43
+ }
44
+
45
+ h5 {
46
+ font-size: 12pt;
47
+ font-weight: 700;
48
+ }
49
+
50
+ h6 {
51
+ font-size: 12pt;
52
+ font-weight: 700;
53
+ }
54
+
55
+ blockquote {
56
+ margin: 1.5em;
57
+ padding: 1em;
58
+ font-size: 10pt;
59
+ }
60
+
61
+ img,
62
+ img.left {
63
+ float: left;
64
+ margin: 1em 1.5em 1.5em 0;
65
+ }
66
+
67
+ img.right {
68
+ float: right;
69
+ margin: 1em 0 1.5em 1.5em;
70
+ }
71
+
72
+ a img {
73
+ border: none;
74
+ }
75
+
76
+ a:link,
77
+ a:visited {
78
+ color: #00f;
79
+ font-weight: 700;
80
+ text-decoration: underline;
81
+ background: transparent;
82
+ }
83
+
84
+ a:link[href^="http://"]:after,
85
+ a[href^="http://"]:visited:after {
86
+ content: " (" attr(href) ") ";
87
+ font-size: 90%;
88
+ }
89
+
90
+ a[href^="http://"] {
91
+ color: #00f;
92
+ }
93
+
94
+ table {
95
+ margin: 1px;
96
+ text-align: left;
97
+
98
+ th {
99
+ border-bottom: 1px solid #333;
100
+ font-weight: 700;
101
+ }
102
+
103
+ td {
104
+ border-bottom: 1px solid #333;
105
+ }
106
+
107
+ th, td {
108
+ padding: 4px 10px 4px 0;
109
+ }
110
+
111
+ tfoot {
112
+ font-style: italic;
113
+ }
114
+
115
+ caption {
116
+ background: #fff;
117
+ margin-bottom: 2em;
118
+ text-align: left;
119
+ }
120
+
121
+ thead {
122
+ display: table-header-group;
123
+ }
124
+
125
+ tr {
126
+ page-break-inside: avoid;
127
+ }
128
+ }
129
+ }