refinerycms-css_and_js_files 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ module Admin
2
+ class CssAndJsFilesController < Admin::BaseController
3
+
4
+ crudify :css_and_js_file,
5
+ :title_attribute => 'name', :xhr_paging => true
6
+
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ class CssAndJsFile < ActiveRecord::Base
2
+
3
+ acts_as_indexed :fields => [:name, :file_type, :content]
4
+
5
+ validates :name, :presence => true
6
+ validates_uniqueness_of :name, :scope => [:file_type]
7
+ scope :css, where(:file_type => 'css')
8
+ scope :js, where(:file_type => 'js')
9
+
10
+ after_save :modify_file
11
+
12
+ def modify_file
13
+ dir = (self.file_type == 'js' ? "javascripts" : "stylesheets")
14
+ old_file =Rails.root+"public/#{dir}/_#{CssAndJsFile.find(self.id).name}.#{self.file_type}"
15
+ File.delete(old_file) if File.exist?(old_file)
16
+ file_name = Rails.root+"public/#{dir}/#{self.name}.#{self.file_type}"
17
+ File.exist?(file_name) ? open(file_name, 'w'){|f| f<< "\n\n/* Updated on #{Time.now}*/\n\n"+self.content} : (File.new(file_name, "w") << "\n\n/* Updated on #{Time.now}*/\n\n"+self.content)
18
+ end
19
+
20
+ def file_name
21
+ self.name+"."+self.file_type
22
+ end
23
+
24
+ def path
25
+ dir = (self.file_type == 'js' ? "javascripts" : "stylesheets")
26
+ Rails.root+"public/#{dir}/#{self.name}.#{self.file_type}"
27
+ end
28
+
29
+ end
@@ -0,0 +1,28 @@
1
+ <ul>
2
+ <% if Admin::CssAndJsFilesController.searchable? %>
3
+ <li>
4
+ <%= render :partial => "/shared/admin/search",
5
+ :locals => {
6
+ :url => admin_css_and_js_files_url
7
+ } %>
8
+ </li>
9
+ <% end %>
10
+ <li>
11
+ <%= link_to t('.create_new'), new_admin_css_and_js_file_url,
12
+ :class => "add_icon" %>
13
+ </li>
14
+ <% if !searching? and Admin::CssAndJsFilesController.sortable? and CssAndJsFile.count > 1 %>
15
+ <li>
16
+ <%= link_to t('.reorder', :what => "Css And Js Files"),
17
+ admin_css_and_js_files_url,
18
+ :id => "reorder_action",
19
+ :class => "reorder_icon" %>
20
+
21
+ <%= link_to t('.reorder_done', :what => "Css And Js Files"),
22
+ admin_css_and_js_files_url,
23
+ :id => "reorder_action_done",
24
+ :style => "display: none;",
25
+ :class => "reorder_icon" %>
26
+ </li>
27
+ <% end %>
28
+ </ul>
@@ -0,0 +1,15 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(css_and_js_file) -%>">
2
+ <span class='title'>
3
+ <%= css_and_js_file.file_name %>
4
+ <span class="preview">&nbsp;</span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_css_and_js_file_path(css_and_js_file),
8
+ :title => t('.edit') %>
9
+ <%= link_to refinery_icon_tag("delete.png"), admin_css_and_js_file_path(css_and_js_file),
10
+ :class => "cancel confirm-delete",
11
+ :title => t('.delete'),
12
+ :confirm => t('message', :scope => 'shared.admin.delete', :title => css_and_js_file.name),
13
+ :method => :delete %>
14
+ </span>
15
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @css_and_js_files %>
2
+ <%= render :partial => "sortable_list" %>
@@ -0,0 +1,36 @@
1
+ <%= form_for [:admin, @css_and_js_file] do |f| -%>
2
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @css_and_js_file,
4
+ :include_object_name => true
5
+ } %>
6
+
7
+ <div class='field'>
8
+ <%= f.label :name -%>
9
+ <%= f.text_field :name, :class => 'larger widest' -%>
10
+ </div>
11
+
12
+ <div class='field'>
13
+ <%= f.label :file_type -%>
14
+ <%= f.select :file_type, ['js', 'css'] -%>
15
+ </div>
16
+
17
+ <div class='field'>
18
+ <%= f.label :content -%>
19
+ <%= f.text_area :content, :class => 'widest' -%>
20
+ </div>
21
+
22
+ <%= render :partial => "/shared/admin/form_actions",
23
+ :locals => {
24
+ :f => f,
25
+ :continue_editing => false,
26
+ :delete_title => t('delete', :scope => 'admin.css_and_js_files.css_and_js_file'),
27
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @css_and_js_file.name)
28
+ } %>
29
+ <% end -%>
30
+ <% content_for :javascripts do %>
31
+ <script>
32
+ $(document).ready(function(){
33
+ page_options.init(false, '', '');
34
+ });
35
+ </script>
36
+ <% end %>
@@ -0,0 +1,18 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <% if @css_and_js_files.any? %>
5
+ <div class='pagination_container'>
6
+ <%= render :partial => 'css_and_js_files' %>
7
+ </div>
8
+ <% else %>
9
+ <p>
10
+ <% unless searching? %>
11
+ <strong>
12
+ <%= t('.no_items_yet') %>
13
+ </strong>
14
+ <% else %>
15
+ <%= t('no_results', :scope => 'shared.admin.search') %>
16
+ <% end %>
17
+ </p>
18
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'css_and_js_file', :collection => @css_and_js_files %>
3
+ </ul>
4
+ <%= render :partial => "/shared/admin/sortable_list",
5
+ :locals => {
6
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true
7
+ } %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,10 @@
1
+ <section id='records'>
2
+ <%= render :partial => 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render :partial => 'actions' %>
6
+ </aside>
7
+ <%= render :partial => '/shared/admin/make_sortable',
8
+ :locals => {
9
+ :tree => false
10
+ } if !searching? and Admin::CssAndJsFilesController.sortable? and CssAndJsFile.count > 1 %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,25 @@
1
+ en:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ css_and_js_files:
8
+ title: Css And Js Files
9
+ admin:
10
+ css_and_js_files:
11
+ actions:
12
+ create_new: Add New Css And Js File
13
+ reorder: Reorder Css And Js Files
14
+ reorder_done: Done Reordering Css And Js Files
15
+ records:
16
+ title: Css And Js Files
17
+ sorry_no_results: Sorry! There are no results found.
18
+ no_items_yet: There are no Css And Js Files yet. Click "Add New Css And Js File" to add your first css and js file.
19
+ css_and_js_file:
20
+ view_live_html: View this css and js file live <br/><em>(opens in a new window)</em>
21
+ edit: Edit this css and js file
22
+ delete: Remove this css and js file forever
23
+ css_and_js_files:
24
+ show:
25
+ other: Other Css And Js Files
@@ -0,0 +1,25 @@
1
+ lolcat:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: IMAGE
6
+ plugins:
7
+ css_and_js_files:
8
+ title: Css And Js Files
9
+ admin:
10
+ css_and_js_files:
11
+ actions:
12
+ create_new: CREATE NEW Css And Js File
13
+ reorder: REORDR Css And Js Files
14
+ reorder_done: DUN REORDERIN Css And Js Files
15
+ records:
16
+ title: Css And Js Files
17
+ sorry_no_results: SRY! THAR R NO RESULTS FINDZ.
18
+ no_items_yet: THAR R NO Css And Js Files YET. CLICK "CREATE NEW Css And Js File" 2 ADD UR FURST css and js file.
19
+ css_and_js_file:
20
+ view_live_html: VIEW DIS css and js file LIV <BR/><EM>(OPENS IN NEW WINDOW)</EM>
21
+ edit: EDIT DIS css and js file
22
+ delete: REMOOV DIS css and js file FOREVR
23
+ css_and_js_files:
24
+ show:
25
+ other: OTHR Css And Js Files
@@ -0,0 +1,21 @@
1
+ nb:
2
+ plugins:
3
+ css_and_js_files:
4
+ title: Css And Js Files
5
+ admin:
6
+ css_and_js_files:
7
+ actions:
8
+ create_new: Lag en ny Css And Js File
9
+ reorder: Endre rekkefølgen på Css And Js Files
10
+ reorder_done: Ferdig å endre rekkefølgen Css And Js Files
11
+ records:
12
+ title: Css And Js Files
13
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
14
+ no_items_yet: Det er ingen Css And Js Files enda. Klikk på "Lag en ny Css And Js File" for å legge til din første css and js file.
15
+ css_and_js_file:
16
+ view_live_html: Vis hvordan denne css and js file ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
17
+ edit: Rediger denne css and js file
18
+ delete: Fjern denne css and js file permanent
19
+ css_and_js_files:
20
+ show:
21
+ other: Andre Css And Js Files
@@ -0,0 +1,21 @@
1
+ nl:
2
+ plugins:
3
+ css_and_js_files:
4
+ title: Css And Js Files
5
+ admin:
6
+ css_and_js_files:
7
+ actions:
8
+ create_new: Maak een nieuwe Css And Js File
9
+ reorder: Wijzig de volgorde van de Css And Js Files
10
+ reorder_done: Klaar met het wijzingen van de volgorde van de Css And Js Files
11
+ records:
12
+ title: Css And Js Files
13
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
14
+ no_items_yet: Er zijn nog geen Css And Js Files. Druk op 'Maak een nieuwe Css And Js File' om de eerste aan te maken.
15
+ css_and_js_file:
16
+ view_live_html: Bekijk deze css and js file op de website <br/><em>(opent een nieuw venster)</em>
17
+ edit: Bewerk deze css and js file
18
+ delete: Verwijder deze css and js file voor eeuwig
19
+ css_and_js_files:
20
+ show:
21
+ other: Andere Css And Js Files
@@ -0,0 +1,9 @@
1
+ Refinery::Application.routes.draw do
2
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
3
+ resources :css_and_js_files, :except => :show do
4
+ collection do
5
+ post :update_positions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class RefinerycmsCssAndJsFilesGenerator < Rails::Generators::NamedBase
4
+
5
+ include Rails::Generators::Migration
6
+
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ argument :name, :type => :string, :default => 'css_and_js_files'
9
+
10
+ def generate
11
+ Dir.glob(File.expand_path('../templates/**/**', __FILE__)).each do |path|
12
+ template path, plugin_path_for(path) unless File.directory?(path)
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ def plugin_path_for(path)
19
+ path = path.gsub(File.dirname(__FILE__) + "/templates/", "vendor/engines/#{plural_name}/")
20
+ path = path.gsub("plural_name", plural_name)
21
+ path = path.gsub("singular_name", singular_name)
22
+ path = path.gsub(".migration", '')
23
+
24
+ # hack can be removed after issue is fixed
25
+ next_migration_number = ActiveRecord::Generators::Base.next_migration_number(File.dirname(__FILE__))
26
+ path = path.gsub("migration_number", next_migration_number)
27
+
28
+ # replace our local db path with the app one instead.
29
+ path = path.gsub("/db/", "/../../../db/")
30
+ end
31
+
32
+ end
33
+
34
+ require 'rails/generators/named_base'
35
+ require 'rails/generators/migration'
36
+ require 'rails/generators/active_model'
37
+ require 'active_record'
38
+
39
+ module ActiveRecord
40
+ module Generators
41
+ class Base < Rails::Generators::NamedBase #:nodoc:
42
+ include Rails::Generators::Migration
43
+
44
+ # Implement the required interface for Rails::Generators::Migration.
45
+ def self.next_migration_number(dirname) #:nodoc:
46
+ next_migration_number = current_migration_number(dirname) + 1
47
+ if ActiveRecord::Base.timestamped_migrations
48
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
49
+ else
50
+ "%.3d" % next_migration_number
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ class CreateStructureForCssAndJsFiles < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :css_and_js_files do |t|
4
+ t.string :name
5
+ t.string :file_type
6
+ t.text :content
7
+ t.integer :position
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :css_and_js_files, :id
13
+
14
+ load(Rails.root.join('db', 'seeds', 'css_and_js_file.rb'))
15
+ end
16
+
17
+ def self.down
18
+ UserPlugin.destroy_all({:name => "css_and_js_file"})
19
+
20
+ Page.delete_all({:link_url => "/css_and_js_file"})
21
+
22
+ drop_table :css_and_js_files
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ User.find(:all).each do |user|
2
+ user.plugins.create({
3
+ :name => "css_and_js_file",
4
+ :position => (user.plugins.maximum(:position) || -1) +1
5
+ }) unless user.plugins.find_by_name('css_and_js_file').present?
6
+ end
7
+
8
+ unless Page.find_by_link_url('/css_and_js_file').present?
9
+ page = Page.create({
10
+ :title => "CssAndJsFile",
11
+ :link_url => "/css_and_js_file",
12
+ :menu_match => "\/css_and_js_file(|\/.+?)",
13
+ :deletable => false,
14
+ :position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1)
15
+ })
16
+ Page.default_parts.each do |default_page_part|
17
+ page.parts.create(:title => default_page_part, :body => nil)
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'refinerycms-base'
2
+
3
+ module Refinery
4
+ module CssAndJsFiles
5
+ class Engine < Rails::Engine
6
+ initializer "static assets" do |app|
7
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
8
+ end
9
+
10
+ config.after_initialize do
11
+ Refinery::Plugin.register do |plugin|
12
+ plugin.name = "css_and_js_files"
13
+ plugin.activity = {
14
+ :class => CssAndJsFile,
15
+ :title => 'name'
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :css_and_js_files do
4
+
5
+ # call this task my running: rake refinery:css_and_js_files:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-css_and_js_files
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Surat Pyari
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-29 00:00:00 +05:30
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Ruby on Rails Css And Js Files engine for Refinery CMS. This engine allows you to write/edit css and javascript files without restarting the server.
22
+ email: suratpyari.db21@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/generators/refinerycms_css_and_js_files_generator.rb
31
+ - lib/generators/templates/db/migrate/migration_number_create_structure_for_css_and_js_files.rb
32
+ - lib/generators/templates/db/seeds/css_and_js_file.rb
33
+ - lib/refinerycms-css_and_js_files.rb
34
+ - lib/tasks/css_and_js_files.rake
35
+ - config/locales/en.yml
36
+ - config/locales/lolcat.yml
37
+ - config/locales/nb.yml
38
+ - config/locales/nl.yml
39
+ - config/routes.rb
40
+ - app/controllers/admin/css_and_js_files_controller.rb
41
+ - app/models/css_and_js_file.rb
42
+ - app/views/admin/css_and_js_files/_actions.html.erb
43
+ - app/views/admin/css_and_js_files/_css_and_js_file.html.erb
44
+ - app/views/admin/css_and_js_files/_css_and_js_files.html.erb
45
+ - app/views/admin/css_and_js_files/_form.html.erb
46
+ - app/views/admin/css_and_js_files/_records.html.erb
47
+ - app/views/admin/css_and_js_files/_sortable_list.html.erb
48
+ - app/views/admin/css_and_js_files/edit.html.erb
49
+ - app/views/admin/css_and_js_files/index.html.erb
50
+ - app/views/admin/css_and_js_files/new.html.erb
51
+ has_rdoc: true
52
+ homepage:
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.6.2
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Css And Js Files engine for Refinery CMS
85
+ test_files: []
86
+