radiant-sheets-extension 1.0.0.pre

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 (53) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +33 -0
  3. data/Rakefile +129 -0
  4. data/app/controllers/admin/scripts_controller.rb +13 -0
  5. data/app/controllers/admin/sheet_resource_controller.rb +54 -0
  6. data/app/controllers/admin/styles_controller.rb +13 -0
  7. data/app/helpers/admin/scripts_helper.rb +5 -0
  8. data/app/helpers/admin/styles_helper.rb +5 -0
  9. data/app/models/javascript_page.rb +16 -0
  10. data/app/models/sheet.rb +93 -0
  11. data/app/models/stylesheet_page.rb +16 -0
  12. data/app/views/admin/scripts/edit.html.haml +30 -0
  13. data/app/views/admin/scripts/index.html.haml +33 -0
  14. data/app/views/admin/scripts/new.html.haml +30 -0
  15. data/app/views/admin/sheets/_edit_scripts.html.haml +40 -0
  16. data/app/views/admin/sheets/_upload_script.html.haml +16 -0
  17. data/app/views/admin/styles/edit.html.haml +30 -0
  18. data/app/views/admin/styles/index.html.haml +33 -0
  19. data/app/views/admin/styles/new.html.haml +30 -0
  20. data/config/locales/en.yml +17 -0
  21. data/config/routes.rb +6 -0
  22. data/cucumber.yml +1 -0
  23. data/features/admin/managing_javascripts.feature +147 -0
  24. data/features/admin/managing_stylesheets.feature +108 -0
  25. data/features/support/env.rb +11 -0
  26. data/features/support/paths.rb +11 -0
  27. data/lib/coffee_filter.rb +5 -0
  28. data/lib/javascript_tags.rb +58 -0
  29. data/lib/radiant-sheets-extension/version.rb +3 -0
  30. data/lib/radiant-sheets-extension.rb +2 -0
  31. data/lib/sass_filter.rb +18 -0
  32. data/lib/scss_filter.rb +19 -0
  33. data/lib/stylesheet_tags.rb +61 -0
  34. data/lib/tasks/sheets_extension_tasks.rake +79 -0
  35. data/public/images/admin/javascript.png +0 -0
  36. data/public/images/admin/stylesheet.png +0 -0
  37. data/radiant-sheets-extension.gemspec +32 -0
  38. data/sass.html +82 -0
  39. data/sheets_extension.rb +96 -0
  40. data/spec/controllers/admin/scripts_controller_spec.rb +123 -0
  41. data/spec/controllers/admin/styles_controller_spec.rb +124 -0
  42. data/spec/datasets/javascripts_dataset.rb +15 -0
  43. data/spec/datasets/stylesheets_dataset.rb +17 -0
  44. data/spec/helpers/admin/scripts_helper_spec.rb +5 -0
  45. data/spec/helpers/admin/styles_helper_spec.rb +5 -0
  46. data/spec/lib/javascript_tags_spec.rb +36 -0
  47. data/spec/lib/stylesheet_tags_spec.rb +41 -0
  48. data/spec/models/javascript_page_spec.rb +80 -0
  49. data/spec/models/page_spec.rb +5 -0
  50. data/spec/models/stylesheet_page_spec.rb +80 -0
  51. data/spec/spec.opts +6 -0
  52. data/spec/spec_helper.rb +36 -0
  53. metadata +169 -0
@@ -0,0 +1,17 @@
1
+ ---
2
+ en:
3
+ create_javascript: Create Javascript
4
+ create_stylesheet: Create Stylesheet
5
+ edit_javascript: Edit Javascript
6
+ edit_stylesheet: Edit Stylesheet
7
+ new_javascript: New Javascript
8
+ new_stylesheet: New Stylesheet
9
+ path: Path
10
+ sheets: Sheets
11
+ upload: Upload
12
+ stylesheet_page: Stylesheet
13
+ javascript_page: Javascript
14
+ sheets:
15
+ root_required: "You must first publish a homepage before you may create a %{model}."
16
+ no_styles: 'No Stylesheets'
17
+ no_scripts: 'No Javascripts'
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.namespace :admin, :collection => { :upload => :post } do |admin|
3
+ admin.resources :styles
4
+ admin.resources :scripts
5
+ end
6
+ end
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,147 @@
1
+ Feature: Managing javascripts
2
+ In order to create, modify, and delete content from the website
3
+ a content editor
4
+ wants to manipulate javascripts in the admin interface
5
+
6
+ Scenario: Limiting access
7
+ Given I am logged in as "existing"
8
+ When I go to the "scripts" admin page
9
+ Then I should see "You must have developer or administrator privileges to edit javascripts."
10
+
11
+ Scenario: Listing javascripts
12
+ Given I am logged in as "designer"
13
+ When I go to the "scripts" admin page
14
+ Then I should see "Javascripts"
15
+ Then I should see "site.js"
16
+ And I should see "coffee.js"
17
+ And I should see "Coffee"
18
+ And I should see "New Javascript"
19
+
20
+ Scenario: Creating javascripts
21
+ Given I am logged in as "designer"
22
+ When I go to the "scripts" admin page
23
+ And I follow "New Javascript"
24
+ And I fill in "Slug" with "cuke.js"
25
+ And I press "Create Javascript"
26
+ Then I should see "Javascripts"
27
+ And I should see "cuke.js"
28
+ And I should see "New Javascript"
29
+
30
+ Scenario: Editing javascripts
31
+ When I go to "/js/site.js"
32
+ Then the page should render
33
+ """
34
+ alert("site!");
35
+ """
36
+ When I am logged in as "designer"
37
+ When I go to the "scripts" admin page
38
+ And I follow "site.js"
39
+ And I fill in "Slug" with "changed.js"
40
+ And I fill in "Body" with "alert('site changed!');"
41
+ And I press "Save Changes"
42
+ Then I should see "changed.js"
43
+ And I follow "Logout"
44
+ And I go to "/js/changed.js"
45
+ And the page should render
46
+ """
47
+ alert('site changed!');
48
+ """
49
+
50
+ Scenario: Rendering Javascripts
51
+ Given I am logged in as "designer"
52
+ When I go to the "scripts" admin page
53
+ And I follow "New Javascript"
54
+ And I fill in "Slug" with "styled.js"
55
+ And I fill in the "Body" content with the text
56
+ """
57
+ var s = {};
58
+ <r:javascript slug="site.js" />
59
+ """
60
+ And I press "Create Javascript"
61
+ And I go to "/js/styled.js"
62
+ Then the page should render
63
+ """
64
+ var s = {};
65
+ alert("site!");
66
+ """
67
+
68
+ Scenario: Rendering CoffeeScript
69
+ Given I am logged in as "designer"
70
+ When I go to the "scripts" admin page
71
+ And I follow "New Javascript"
72
+ And I fill in "Slug" with "mocha.js"
73
+ And I fill in the "Body" content with the text
74
+ """
75
+ # Assignment:
76
+ number = 42
77
+ opposite = true
78
+
79
+ # Conditions:
80
+ number = -42 if opposite
81
+
82
+ # Functions:
83
+ square = (x) -> x * x
84
+
85
+ # Arrays:
86
+ list = [1, 2, 3, 4, 5]
87
+
88
+ # Objects:
89
+ math =
90
+ root: Math.sqrt
91
+ square: square
92
+ cube: (x) -> x * square x
93
+
94
+ # Splats:
95
+ race = (winner, runners...) ->
96
+ print winner, runners
97
+
98
+ # Existence:
99
+ alert "I knew it!" if elvis?
100
+
101
+ # Array comprehensions:
102
+ cubes = (math.cube num for num in list)
103
+ """
104
+ And I select "Coffee" from "Filter"
105
+ And I press "Create Javascript"
106
+ And I go to "/js/mocha.js"
107
+ Then the page should render
108
+ """
109
+ (function() {
110
+ var cubes, list, math, num, number, opposite, race, square;
111
+ var __slice = Array.prototype.slice;
112
+ number = 42;
113
+ opposite = true;
114
+ if (opposite) {
115
+ number = -42;
116
+ }
117
+ square = function(x) {
118
+ return x * x;
119
+ };
120
+ list = [1, 2, 3, 4, 5];
121
+ math = {
122
+ root: Math.sqrt,
123
+ square: square,
124
+ cube: function(x) {
125
+ return x * square(x);
126
+ }
127
+ };
128
+ race = function() {
129
+ var runners, winner;
130
+ winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
131
+ return print(winner, runners);
132
+ };
133
+ if (typeof elvis !== "undefined" && elvis !== null) {
134
+ alert("I knew it!");
135
+ }
136
+ cubes = (function() {
137
+ var _i, _len, _results;
138
+ _results = [];
139
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
140
+ num = list[_i];
141
+ _results.push(math.cube(num));
142
+ }
143
+ return _results;
144
+ })();
145
+ }).call(this);
146
+ """
147
+
@@ -0,0 +1,108 @@
1
+ Feature: Managing stylesheets
2
+ In order to create, modify, and delete content from the website
3
+ a content editor
4
+ wants to manipulate stylesheets in the admin interface
5
+
6
+ Scenario: Limiting access
7
+ Given I am logged in as "existing"
8
+ When I go to the "styles" admin page
9
+ Then I should see "You must have developer or administrator privileges to edit stylesheets."
10
+
11
+ Scenario: Listing stylesheets
12
+ Given I am logged in as "designer"
13
+ When I go to the "styles" admin page
14
+ Then I should see "Stylesheets"
15
+ And I should see "site.css"
16
+ And I should see "sassy.sass"
17
+ And I should see "Sass"
18
+ And I should see "New Stylesheet"
19
+
20
+ Scenario: Creating stylesheets
21
+ Given I am logged in as "designer"
22
+ When I go to the "styles" admin page
23
+ And I follow "New Stylesheet"
24
+ And I fill in "Slug" with "cuke.css"
25
+ And I press "Create Stylesheet"
26
+ Then I should see "Stylesheets"
27
+ And I should see "cuke.css"
28
+ And I should see "New Stylesheet"
29
+
30
+ Scenario: Editing stylesheets
31
+ When I go to "/css/site.css"
32
+ Then the page should render
33
+ """
34
+ p { color: blue; }
35
+ """
36
+ When I am logged in as "designer"
37
+ When I go to the "styles" admin page
38
+ And I follow "site.css"
39
+ And I fill in "Slug" with "changed.css"
40
+ And I fill in "Body" with "p { color: red; } /* I added this comment */"
41
+ And I press "Save Changes"
42
+ Then I should see "changed.css"
43
+ And I follow "Logout"
44
+ And I go to "/css/changed.css"
45
+ And the page should render
46
+ """
47
+ p { color: red; } /* I added this comment */
48
+ """
49
+
50
+ Scenario: Rendering CSS
51
+ Given I am logged in as "designer"
52
+ When I go to the "styles" admin page
53
+ And I follow "New Stylesheet"
54
+ And I fill in "Slug" with "styled.css"
55
+ And I fill in the "Body" content with the text
56
+ """
57
+ body { color: red; }
58
+ <r:stylesheet slug="site.css" />
59
+ """
60
+ And I press "Create Stylesheet"
61
+ And I go to "/css/styled.css"
62
+ Then the page should render
63
+ """
64
+ body { color: red; }
65
+ p { color: blue; }
66
+ """
67
+
68
+ Scenario: Rendering Sass
69
+ Given I am logged in as "designer"
70
+ When I go to the "styles" admin page
71
+ And I follow "New Stylesheet"
72
+ And I fill in "Slug" with "sassed.css"
73
+ And I fill in the "Body" content with the text
74
+ """
75
+ body
76
+ font-size: 1em
77
+ """
78
+ And I select "Sass" from "Filter"
79
+ And I press "Create Stylesheet"
80
+ And I go to "/css/sassed.css"
81
+ Then the page should render
82
+ """
83
+ body{font-size:1em}
84
+ """
85
+
86
+ Scenario: Rendering SCSS
87
+ Given I am logged in as "designer"
88
+ When I go to the "styles" admin page
89
+ And I follow "New Stylesheet"
90
+ And I fill in "Slug" with "sassed.css"
91
+ And I fill in the "Body" content with the text
92
+ """
93
+ p {
94
+ a {
95
+ color: blue;
96
+ line-height: 1.9;
97
+ }
98
+ color: red;
99
+ }
100
+ """
101
+ And I select "SCSS" from "Filter"
102
+ And I press "Create Stylesheet"
103
+ And I go to "/css/sassed.css"
104
+ Then the page should render
105
+ """
106
+ p{color:red}p a{color:blue;line-height:1.9}
107
+ """
108
+
@@ -0,0 +1,11 @@
1
+ # Sets up the Rails environment for Cucumber
2
+ ENV["RAILS_ENV"] = "test"
3
+ # Extension root
4
+ extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
5
+ require extension_env+'.rb'
6
+
7
+ Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/}
8
+
9
+ Cucumber::Rails::World.class_eval do
10
+ dataset :users_and_pages, :stylesheets, :javascripts
11
+ end
@@ -0,0 +1,11 @@
1
+ module NavigationHelpers
2
+
3
+ PathMatchers = {} unless defined?(PathMatchers)
4
+ PathMatchers.merge!({
5
+ /styles/i => 'admin_styles_path',
6
+ /scripts/i => 'admin_scripts_path'
7
+ })
8
+
9
+ end
10
+
11
+ World(NavigationHelpers)
@@ -0,0 +1,5 @@
1
+ class CoffeeFilter < TextFilter
2
+ def filter(text)
3
+ CoffeeScript.compile text
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ module JavascriptTags
2
+ include Radiant::Taggable
3
+ class TagError < StandardError; end
4
+
5
+ desc %{
6
+ Renders the content from or a reference to the javascript specified in the @slug@
7
+ attribute. Additionally, the @as@ attribute can be used to make the tag render
8
+ as one of the following:
9
+
10
+ * with no @as@ value the javascript's content is rendered by default.
11
+ * @inline@ - wraps the javascript's content in an (X)HTML @<script>@ element.
12
+ * @url@ - the full path to the javascript.
13
+ * @link@ - embeds the url in an (X)HTML @<script>@ element (creating a link to the external javascript).
14
+
15
+ *Additional Options:*
16
+ When rendering @as="inline"@ or @as="link"@, the (X)HTML @type@ attribute
17
+ is automatically be set to the default javascript content-type.
18
+ You can overrride this attribute or add additional ones by passing extra
19
+ attributes to the @<r:javascript>@ tag.
20
+
21
+ *Usage:*
22
+
23
+ <pre><code><r:javascript slug="site.css" as="inline"
24
+ type="text/custom" id="my_id" />
25
+ <r:javascript slug="other.js" as="link" /></code></pre>
26
+
27
+ The above example will produce the following:
28
+
29
+ <pre><code> <script type="text/custom" id="my_id">
30
+ //<![CDATA[
31
+ var your_script = 'this content';
32
+ //]]>
33
+ </script>
34
+ <script type="text/javascript" src="/js/other.js"></script></code></pre>
35
+ }
36
+ tag 'javascript' do |tag|
37
+ slug = (tag.attr['slug'] || tag.attr['name'])
38
+ raise TagError.new("`javascript' tag must contain a `slug' attribute.") unless slug
39
+ if (javascript = JavascriptPage.find_by_slug(slug))
40
+ mime_type = tag.attr['type'] || javascript.headers['Content-Type']
41
+ url = javascript.url.sub(/\/$/,'') + '?' + javascript.updated_at.to_i.to_s
42
+ optional_attributes = tag.attr.except('slug', 'name', 'as', 'type').inject('') { |s, (k, v)| s << %{#{k}="#{v}" } }.strip
43
+ optional_attributes = " #{optional_attributes}" unless optional_attributes.empty?
44
+ case tag.attr['as']
45
+ when 'url'
46
+ url
47
+ when 'inline'
48
+ %{<script type="#{mime_type}"#{optional_attributes}>\n//<![CDATA[\n#{javascript.render_part('body')}\n//]]>\n</script>}
49
+ when 'link'
50
+ %{<script type="#{mime_type}" src="#{url}"#{optional_attributes}></script>}
51
+ else
52
+ javascript.render_part('body')
53
+ end
54
+ else
55
+ raise TagError.new("javascript #{slug} not found")
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module RadiantSheetsExtension
2
+ VERSION = '1.0.0.pre'
3
+ end
@@ -0,0 +1,2 @@
1
+ module RadiantSheetsExtension
2
+ end
@@ -0,0 +1,18 @@
1
+ class SassFilter < TextFilter
2
+ description_file File.dirname(__FILE__) + "/../sass.html"
3
+
4
+ description "Sass is a meta-language on top of CSS that's used to describe the style of a document cleanly and structurally, with more power than flat CSS allows."
5
+
6
+ def filter(text)
7
+ begin
8
+ options = Compass.sass_engine_options || {:load_paths => []}
9
+ options[:load_paths].unshift "#{RADIANT_ROOT}/public/stylesheets/sass"
10
+ options[:load_paths].unshift "#{Rails.root}/public/stylesheets/sass"
11
+ # this would need some substitions (as in paperclip) to be useful
12
+ # options[:load_paths] += Radiant::Config['sheets.sass_template_paths'].split(',').map(&:strip) if Radiant::Config['sheets.sass_template_paths']
13
+ Sass::Engine.new(text, options).render
14
+ rescue Sass::SyntaxError
15
+ "Syntax Error at line #{$!.sass_line}: " + $!.to_s
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ class ScssFilter < TextFilter
2
+ description_file File.dirname(__FILE__) + "/../scss.html"
3
+
4
+ filter_name 'SCSS'
5
+ description 'SCSS is fully compatible with the syntax of CSS3, while still supporting the full power of Sass.'
6
+
7
+ def filter(text)
8
+ begin
9
+ options = Compass.sass_engine_options || {:load_paths => []}
10
+ options[:load_paths].unshift "#{Rails.root}/public/stylesheets/scss"
11
+ options[:syntax] = :scss
12
+ # this would need some substitions (as in paperclip) to be useful
13
+ # options[:load_paths] += Radiant::Config['sheets.sass_template_paths'].split(',').map(&:strip) if Radiant::Config['sheets.sass_template_paths']
14
+ Sass::Engine.new(text, options).render
15
+ rescue Sass::SyntaxError
16
+ "Syntax Error at line #{$!.sass_line}: " + $!.to_s
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ module StylesheetTags
2
+ include Radiant::Taggable
3
+ class TagError < StandardError; end
4
+
5
+ desc %{
6
+ Renders the content from or a reference to the stylesheet specified in the @slug@
7
+ attribute. Additionally, the @as@ attribute can be used to make the tag render
8
+ as one of the following:
9
+
10
+ * with no @as@ value the stylesheet's content is rendered by default.
11
+ * @inline@ - wraps the stylesheet's content in an (X)HTML @<style>@ element.
12
+ * @url@ - the full path to the stylesheet.
13
+ * @link@ - embeds the url in an (X)HTML @<link>@ element (creating a link to the external stylesheet).
14
+
15
+ *Additional Options:*
16
+ When rendering @as="inline"@ or @as="link"@, the (X)HTML @type@ attribute
17
+ is automatically be set to the default stylesheet content-type.
18
+ You can overrride this attribute or add additional ones by passing extra
19
+ attributes to the @<r:stylesheet>@ tag.
20
+
21
+ *Usage:*
22
+
23
+ <pre><code><r:stylesheet slug="site.css" as="inline"
24
+ type="text/custom" id="my_id" />
25
+ <r:stylesheet slug="other.css" as="link"
26
+ rel="alternate stylesheet" /></code></pre>
27
+
28
+ The above example will produce the following:
29
+
30
+ <pre><code> <style type="text/custom" id="my_id">
31
+ /*<![CDATA[*/
32
+ .your_stylesheet { content: 'here' }
33
+ /*]]>*/
34
+ </style>
35
+ <link rel="alternate stylesheet" type="text/css"
36
+ href="/css/other.css" /></code></pre>
37
+ }
38
+ tag 'stylesheet' do |tag|
39
+ slug = (tag.attr['slug'] || tag.attr['name'])
40
+ raise TagError.new("`stylesheet' tag must contain a `slug' attribute.") unless slug
41
+ if (stylesheet = StylesheetPage.find_by_slug(slug))
42
+ mime_type = tag.attr['type'] || stylesheet.headers['Content-Type']
43
+ url = stylesheet.url.sub(/\/$/,'') + '?' + stylesheet.updated_at.to_i.to_s
44
+ rel = tag.attr.delete('rel') || 'stylesheet'
45
+ optional_attributes = tag.attr.except('slug', 'name', 'as', 'type').inject('') { |s, (k, v)| s << %{#{k}="#{v}" } }.strip
46
+ optional_attributes = " #{optional_attributes}" unless optional_attributes.empty?
47
+ case tag.attr['as']
48
+ when 'url'
49
+ url
50
+ when 'inline'
51
+ %{<style type="#{mime_type}"#{optional_attributes}>\n/*<![CDATA[*/\n#{stylesheet.render_part('body')}\n/*]]>*/\n</style>}
52
+ when 'link'
53
+ %{<link rel="#{rel}" type="#{mime_type}" href="#{url}"#{optional_attributes} />}
54
+ else
55
+ stylesheet.render_part('body')
56
+ end
57
+ else
58
+ raise TagError.new("stylesheet #{slug} not found")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,79 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :sheets do
4
+
5
+ desc "Runs the migration of the Sheets extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ SheetsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ SheetsExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Sheets to the instance public/ directory."
18
+ task :update => :environment do
19
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
20
+ puts "Copying assets from SheetsExtension"
21
+ Dir[SheetsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(SheetsExtension.root, '')
23
+ directory = File.dirname(path)
24
+ mkdir_p RAILS_ROOT + directory, :verbose => false
25
+ cp file, RAILS_ROOT + path, :verbose => false
26
+ end
27
+ unless SheetsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from SheetsExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join SheetsExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = SheetsExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+
54
+ namespace :import do
55
+ desc "Creates new sheets pages from old SNS text_assets"
56
+ task :sns => :environment do
57
+ class TextAsset < ActiveRecord::Base
58
+ belongs_to :created_by, :class_name => 'User'
59
+ belongs_to :updated_by, :class_name => 'User'
60
+ end
61
+ TextAsset.all.each do |ta|
62
+ klass = (ta.class_name + 'Page').constantize
63
+ p "Importing #{klass} #{ta.name}"
64
+ sheet = klass.new_with_defaults
65
+ sheet.part('body').content = ta.content
66
+ sheet.part('body').filter_id = ta.filter_id
67
+ sheet.slug = ta.name
68
+ ta.attributes.each do |attribute, value|
69
+ if !attribute.match(/^(lock_version|id|content|filter_id|name|class_name)$/) && sheet.respond_to?("#{attribute}=")
70
+ sheet.send("#{attribute}=", value)
71
+ end
72
+ end
73
+ sheet.save!
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
Binary file
Binary file
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-sheets-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-sheets-extension"
7
+ s.version = RadiantSheetsExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Radiant CMS Dev Team"]
10
+ s.email = ["radiant@radiantcms.org"]
11
+ s.homepage = "http://radiantcms.org/"
12
+ s.summary = %q{Sheets for Radiant CMS}
13
+ s.description = %q{Manage CSS and Javascript content in Radiant CMS as Sheets, a subset of Pages.}
14
+
15
+ ignores = if File.exist?('.gitignore')
16
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+ s.files = Dir['**/*'] - ignores
21
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
22
+ # s.executables = Dir['bin/*'] - ignores
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_dependency 'sass', '~>3.1.2'
26
+ s.add_dependency 'coffee-script', '~>2.2.0'
27
+
28
+ s.post_install_message = %{
29
+ Add this to your radiant project with:
30
+ config.gem 'radiant-sheets-extension', :version => '~>#{RadiantSheetsExtension::VERSION}'
31
+ }
32
+ end