newsletter 0.0.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 (144) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +26 -0
  6. data/Gemfile.lock +199 -0
  7. data/Guardfile +24 -0
  8. data/LICENSE +22 -0
  9. data/MIT-LICENSE +20 -0
  10. data/Manifest.txt +220 -0
  11. data/Procfile +2 -0
  12. data/README +243 -0
  13. data/README.rdoc +3 -0
  14. data/Rakefile +29 -0
  15. data/app/assets/images/newsletter/.gitkeep +0 -0
  16. data/app/assets/javascripts/newsletter/application.js +15 -0
  17. data/app/assets/stylesheets/newsletter/application.css +13 -0
  18. data/app/controllers/newsletter/application_controller.rb +27 -0
  19. data/app/controllers/newsletter/areas_controller.rb +63 -0
  20. data/app/controllers/newsletter/designs_controller.rb +51 -0
  21. data/app/controllers/newsletter/elements_controller.rb +75 -0
  22. data/app/controllers/newsletter/fields_controller.rb +49 -0
  23. data/app/controllers/newsletter/newsletters_controller.rb +104 -0
  24. data/app/controllers/newsletter/pieces_controller.rb +72 -0
  25. data/app/helpers/newsletter/application_helper.rb +4 -0
  26. data/app/helpers/newsletter/areas_helper.rb +4 -0
  27. data/app/helpers/newsletter/assets_helper.rb +4 -0
  28. data/app/helpers/newsletter/designs_helper.rb +11 -0
  29. data/app/helpers/newsletter/elements_helper.rb +4 -0
  30. data/app/helpers/newsletter/field_values_helper.rb +4 -0
  31. data/app/helpers/newsletter/fields_helper.rb +4 -0
  32. data/app/helpers/newsletter/newsletters_helper.rb +43 -0
  33. data/app/helpers/newsletter/pieces_helper.rb +4 -0
  34. data/app/models/newsletter/area.rb +50 -0
  35. data/app/models/newsletter/asset.rb +31 -0
  36. data/app/models/newsletter/design.rb +160 -0
  37. data/app/models/newsletter/element.rb +169 -0
  38. data/app/models/newsletter/field/inline_asset.rb +67 -0
  39. data/app/models/newsletter/field/text.rb +15 -0
  40. data/app/models/newsletter/field/text_area.rb +15 -0
  41. data/app/models/newsletter/field.rb +115 -0
  42. data/app/models/newsletter/field_value.rb +20 -0
  43. data/app/models/newsletter/newsletter.rb +125 -0
  44. data/app/models/newsletter/piece.rb +96 -0
  45. data/app/models/newsletter.rb +11 -0
  46. data/app/uploaders/newsletter/asset_uploader.rb +51 -0
  47. data/app/views/layouts/newsletter/application.html.erb +135 -0
  48. data/app/views/newsletter/areas/_area.html.erb +49 -0
  49. data/app/views/newsletter/designs/_area_fields.html.erb +4 -0
  50. data/app/views/newsletter/designs/_form.html.erb +41 -0
  51. data/app/views/newsletter/designs/_newsletter_area.html.erb +17 -0
  52. data/app/views/newsletter/designs/edit.html.erb +14 -0
  53. data/app/views/newsletter/designs/index.html.erb +31 -0
  54. data/app/views/newsletter/designs/new.html.erb +9 -0
  55. data/app/views/newsletter/designs/show.html.erb +22 -0
  56. data/app/views/newsletter/elements/_field_fields.html.erb +27 -0
  57. data/app/views/newsletter/elements/_form.html.erb +51 -0
  58. data/app/views/newsletter/elements/_newsletter_field.html.erb +37 -0
  59. data/app/views/newsletter/elements/edit.html.erb +12 -0
  60. data/app/views/newsletter/elements/index.html.erb +32 -0
  61. data/app/views/newsletter/elements/new.html.erb +9 -0
  62. data/app/views/newsletter/elements/show.html.erb +22 -0
  63. data/app/views/newsletter/fields/_form.html.erb +15 -0
  64. data/app/views/newsletter/fields/_inline_asset.html.erb +36 -0
  65. data/app/views/newsletter/fields/_text.html.erb +4 -0
  66. data/app/views/newsletter/fields/_text_area.html.erb +7 -0
  67. data/app/views/newsletter/newsletters/_form.html.erb +21 -0
  68. data/app/views/newsletter/newsletters/_head.html.erb +48 -0
  69. data/app/views/newsletter/newsletters/_newsletter.html.erb +6 -0
  70. data/app/views/newsletter/newsletters/_newsletter_area.html.erb +30 -0
  71. data/app/views/newsletter/newsletters/archive.html.erb +9 -0
  72. data/app/views/newsletter/newsletters/edit.html.erb +37 -0
  73. data/app/views/newsletter/newsletters/index.html.erb +29 -0
  74. data/app/views/newsletter/newsletters/new.html.erb +9 -0
  75. data/app/views/newsletter/newsletters/show.html.erb +6 -0
  76. data/app/views/newsletter/pieces/_form.html.erb +19 -0
  77. data/app/views/newsletter/pieces/edit.html.erb +11 -0
  78. data/app/views/newsletter/pieces/new.html.erb +10 -0
  79. data/app/views/newsletter/pieces/show.html.erb +2 -0
  80. data/assets/docs/index.html +45 -0
  81. data/assets/docs/newsletter_templates/index.html +45 -0
  82. data/config/routes.rb +33 -0
  83. data/db/migrate/001_newsletter_initial.rb +104 -0
  84. data/db/migrate/002_carrier_wave_for_assets.rb +9 -0
  85. data/db/pre-scoped/002_newsletter_scoped.rb +61 -0
  86. data/doc/README_FOR_APP +2 -0
  87. data/doc/newsletter.wiki.txt +130 -0
  88. data/doc/start_rails_engine_with_rspec.txt +43 -0
  89. data/engine_plan.rb +13 -0
  90. data/features/step_definitions/webrat_steps.rb +115 -0
  91. data/features/support/env.rb +17 -0
  92. data/features/support/paths.rb +27 -0
  93. data/lib/deleteable.rb +50 -0
  94. data/lib/newsletter/config.rb +50 -0
  95. data/lib/newsletter/engine.rb +62 -0
  96. data/lib/newsletter/settings.rb +50 -0
  97. data/lib/newsletter/version.rb +3 -0
  98. data/lib/newsletter.rb +7 -0
  99. data/lib/tasks/newsletter.rake +84 -0
  100. data/lib/tasks/newsletter_tasks.rake +4 -0
  101. data/lib/tasks/rspec.rake +158 -0
  102. data/newsletter.gemspec +30 -0
  103. data/newsletters/exports/example-export.yaml +213 -0
  104. data/script/rails +8 -0
  105. data/spec/rcov.opts +2 -0
  106. data/spec/spec.opts +4 -0
  107. data/spec/spec_helper.rb +41 -0
  108. data/spec/test_app/README.rdoc +261 -0
  109. data/spec/test_app/Rakefile +7 -0
  110. data/spec/test_app/app/assets/javascripts/application.js +15 -0
  111. data/spec/test_app/app/assets/stylesheets/application.css +13 -0
  112. data/spec/test_app/app/controllers/application_controller.rb +3 -0
  113. data/spec/test_app/app/helpers/application_helper.rb +2 -0
  114. data/spec/test_app/app/mailers/.gitkeep +0 -0
  115. data/spec/test_app/app/models/.gitkeep +0 -0
  116. data/spec/test_app/app/views/layouts/application.html.erb +14 -0
  117. data/spec/test_app/config/application.rb +65 -0
  118. data/spec/test_app/config/boot.rb +10 -0
  119. data/spec/test_app/config/database.yml +25 -0
  120. data/spec/test_app/config/environment.rb +5 -0
  121. data/spec/test_app/config/environments/development.rb +37 -0
  122. data/spec/test_app/config/environments/production.rb +67 -0
  123. data/spec/test_app/config/environments/test.rb +37 -0
  124. data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
  125. data/spec/test_app/config/initializers/inflections.rb +15 -0
  126. data/spec/test_app/config/initializers/mime_types.rb +5 -0
  127. data/spec/test_app/config/initializers/secret_token.rb +7 -0
  128. data/spec/test_app/config/initializers/session_store.rb +8 -0
  129. data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
  130. data/spec/test_app/config/locales/en.yml +5 -0
  131. data/spec/test_app/config/newsletter.yml +9 -0
  132. data/spec/test_app/config/routes.rb +4 -0
  133. data/spec/test_app/config.ru +4 -0
  134. data/spec/test_app/db/migrate/20131222171229_newsletter_initial.rb +104 -0
  135. data/spec/test_app/db/schema.rb +116 -0
  136. data/spec/test_app/lib/assets/.gitkeep +0 -0
  137. data/spec/test_app/log/.gitkeep +0 -0
  138. data/spec/test_app/public/404.html +26 -0
  139. data/spec/test_app/public/422.html +26 -0
  140. data/spec/test_app/public/500.html +25 -0
  141. data/spec/test_app/public/favicon.ico +0 -0
  142. data/spec/test_app/script/rails +6 -0
  143. data/zeus.json +22 -0
  144. metadata +352 -0
data/README ADDED
@@ -0,0 +1,243 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb" designs
7
+ that are primarily responsible for inserting pre-built data in between HTML tags.
8
+ The model contains the "smart" domain objects (such as Account, Product, Person,
9
+ Post) that holds all the business logic and knows how to persist themselves to
10
+ a database. The controller handles the incoming requests (such as Save New Account,
11
+ Update Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting Started
29
+
30
+ 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
+ and your application name. Ex: rails myapp
32
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
+ 4. Follow the guidelines to start developing your application
35
+
36
+
37
+ == Web Servers
38
+
39
+ By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
+ with a variety of other web servers.
41
+
42
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
43
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
44
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
45
+ More info at: http://mongrel.rubyforge.org
46
+
47
+ Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
48
+ Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
+ FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
+
51
+ == Apache .htaccess example for FCGI/CGI
52
+
53
+ # General Apache options
54
+ AddHandler fastcgi-script .fcgi
55
+ AddHandler cgi-script .cgi
56
+ Options +FollowSymLinks +ExecCGI
57
+
58
+ # If you don't want Rails to look in certain directories,
59
+ # use the following rewrite rules so that Apache won't rewrite certain requests
60
+ #
61
+ # Example:
62
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
63
+ # RewriteRule .* - [L]
64
+
65
+ # Redirect all requests not available on the filesystem to Rails
66
+ # By default the cgi dispatcher is used which is very slow
67
+ #
68
+ # For better performance replace the dispatcher with the fastcgi one
69
+ #
70
+ # Example:
71
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
+ RewriteEngine On
73
+
74
+ # If your Rails application is accessed via an Alias directive,
75
+ # then you MUST also set the RewriteBase in this htaccess file.
76
+ #
77
+ # Example:
78
+ # Alias /myrailsapp /path/to/myrailsapp/public
79
+ # RewriteBase /myrailsapp
80
+
81
+ RewriteRule ^$ index.html [QSA]
82
+ RewriteRule ^([^.]+)$ $1.html [QSA]
83
+ RewriteCond %{REQUEST_FILENAME} !-f
84
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
85
+
86
+ # In case Rails experiences terminal errors
87
+ # Instead of displaying this message you can supply a file here which will be rendered instead
88
+ #
89
+ # Example:
90
+ # ErrorDocument 500 /500.html
91
+
92
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
93
+
94
+
95
+ == Debugging Rails
96
+
97
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
+ will help you debug it and get it back on the rails.
99
+
100
+ First area to check is the application log files. Have "tail -f" commands running
101
+ on the server.log and development.log. Rails will automatically display debugging
102
+ and runtime information to these files. Debugging info will also be shown in the
103
+ browser on requests from 127.0.0.1.
104
+
105
+ You can also log your own messages directly into the log file from your code using
106
+ the Ruby logger class from inside your controllers. Example:
107
+
108
+ class WeblogController < ActionController::Base
109
+ def destroy
110
+ @weblog = Weblog.find(params[:id])
111
+ @weblog.destroy
112
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
113
+ end
114
+ end
115
+
116
+ The result will be a message in your log file along the lines of:
117
+
118
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
+
120
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
121
+
122
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
123
+
124
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
125
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
126
+
127
+ These two online (and free) books will bring you up to speed on the Ruby language
128
+ and also on programming in general.
129
+
130
+
131
+ == Debugger
132
+
133
+ Debugger support is available through the debugger command when you start your Mongrel or
134
+ Webrick server with --debugger. This means that you can break out of execution at any point
135
+ in the code, investigate and change the model, AND then resume execution!
136
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
137
+ Example:
138
+
139
+ class WeblogController < ActionController::Base
140
+ def index
141
+ @posts = Post.find(:all)
142
+ debugger
143
+ end
144
+ end
145
+
146
+ So the controller will accept the action, run the first line, then present you
147
+ with a IRB prompt in the server window. Here you can do things like:
148
+
149
+ >> @posts.inspect
150
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
151
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
152
+ >> @posts.first.title = "hello from a debugger"
153
+ => "hello from a debugger"
154
+
155
+ ...and even better is that you can examine how your runtime objects actually work:
156
+
157
+ >> f = @posts.first
158
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
159
+ >> f.
160
+ Display all 152 possibilities? (y or n)
161
+
162
+ Finally, when you're ready to resume execution, you enter "cont"
163
+
164
+
165
+ == Console
166
+
167
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
+ Here you'll have all parts of the application configured, just like it is when the
169
+ application is running. You can inspect domain models, change values, and save to the
170
+ database. Starting the script without arguments will launch it in the development environment.
171
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
+
173
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
174
+
175
+ == dbconsole
176
+
177
+ You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
+ You would be connected to the database with the credentials defined in database.yml.
179
+ Starting the script without arguments will connect you to the development database. Passing an
180
+ argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
+ Currently works for mysql, postgresql and sqlite.
182
+
183
+ == Description of Contents
184
+
185
+ app
186
+ Holds all the code that's specific to this particular application.
187
+
188
+ app/controllers
189
+ Holds controllers that should be named like weblogs_controller.rb for
190
+ automated URL mapping. All controllers should descend from ApplicationController
191
+ which itself descends from ActionController::Base.
192
+
193
+ app/models
194
+ Holds models that should be named like post.rb.
195
+ Most models will descend from ActiveRecord::Base.
196
+
197
+ app/views
198
+ Holds the design files for the view that should be named like
199
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
+ syntax.
201
+
202
+ app/views/layouts
203
+ Holds the design files for layouts to be used with views. This models the common
204
+ header/footer method of wrapping views. In your views, define a layout using the
205
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
206
+ call <% yield %> to render the view using this layout.
207
+
208
+ app/helpers
209
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
+ for you automatically when using script/generate for controllers. Helpers can be used to
211
+ wrap functionality for your views into methods.
212
+
213
+ config
214
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
+
216
+ db
217
+ Contains the database schema in schema.rb. db/migrate contains all
218
+ the sequence of Migrations for your schema.
219
+
220
+ doc
221
+ This directory is where your application documentation will be stored when generated
222
+ using <tt>rake doc:app</tt>
223
+
224
+ lib
225
+ Application specific libraries. Basically, any kind of custom code that doesn't
226
+ belong under controllers, models, or helpers. This directory is in the load path.
227
+
228
+ public
229
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
230
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
+ set as the DOCUMENT_ROOT of your web server.
232
+
233
+ script
234
+ Helper scripts for automation and generation.
235
+
236
+ test
237
+ Unit and functional tests along with fixtures. When using the script/generate scripts, design
238
+ test files will be generated for you and placed in this directory.
239
+
240
+ vendor
241
+ External libraries that the application depends on. Also includes the plugins subdirectory.
242
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
243
+ This directory is in the load path.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Newsletter
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Newsletter'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
File without changes
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,27 @@
1
+ require 'dynamic_form'
2
+ require 'nested_form'
3
+ class Newsletter::ApplicationController < ActionController::Base
4
+ layout 'newsletter/application'
5
+ helper_method :title, :use_show_for_resources?, :site_url, :show_title?
6
+
7
+ def title(value=nil)
8
+ @title = value if value.present?
9
+ @title
10
+ end
11
+
12
+ def show_title?
13
+ true
14
+ end
15
+
16
+ def use_show_for_resources?
17
+ ::Newsletter.use_show_for_resources
18
+ rescue
19
+ false
20
+ end
21
+
22
+ def site_url
23
+ ::Newsletter.site_url
24
+ rescue
25
+ "#{default_url_options[:protocol]||'http'}://#{default_url_options[:domain]}"
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ module Newsletter
2
+ class AreasController < ::Newsletter::ApplicationController
3
+
4
+ before_filter :find_area, :except => [:create, :new, :index]
5
+ before_filter :find_design, :except => [:destroy,:sort]
6
+
7
+ def sort
8
+ @newsletter = Newsletter.find(params[:newsletter_id])
9
+ @area.pieces.active.by_newsletter(@newsletter).each do | piece |
10
+ piece.update_attribute(:sequence, params["piece"].index(piece.id.to_s).to_i+1)
11
+ end
12
+ head :ok
13
+ end
14
+
15
+ def index
16
+ @areas = Area.find(:all)
17
+ end
18
+
19
+ def show
20
+ end
21
+
22
+ def new
23
+ @newsletter_area = Area.new
24
+ end
25
+
26
+ def edit
27
+ end
28
+
29
+ def create
30
+ @newsletter_area = Area.new(params[:area])
31
+ if @newsletter_area.save
32
+ flash[:notice] = 'Area was successfully created.'
33
+ redirect_to(@newsletter_area)
34
+ else
35
+ render :action => "new"
36
+ end
37
+ end
38
+
39
+ def update
40
+ if @newsletter_area.update_attributes(params[:area])
41
+ flash[:notice] = 'Area was successfully updated.'
42
+ redirect_to(@newsletter_area)
43
+ else
44
+ render :action => "edit"
45
+ end
46
+ end
47
+
48
+ def destroy
49
+ @newsletter_area.destroy
50
+ redirect_to(areas_url)
51
+ end
52
+
53
+ protected
54
+
55
+ def find_design
56
+ @design = Design.find(params[:design_id])
57
+ end
58
+
59
+ def find_area
60
+ @area = Area.find(params[:id])
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,51 @@
1
+ require 'nested_form'
2
+ module Newsletter
3
+ class DesignsController < ::Newsletter::ApplicationController
4
+ before_filter :find_design, :except => [:new, :create, :index]
5
+
6
+ def index
7
+ @designs = Design.find(:all)
8
+ end
9
+
10
+ def show
11
+ @areas = @design.areas.active
12
+ end
13
+
14
+ def new
15
+ @design = Design.new
16
+ end
17
+
18
+ def edit
19
+ end
20
+
21
+ def create
22
+ @design = Design.new(params[:design])
23
+ if @design.save
24
+ flash[:notice] = 'Design was successfully created.'
25
+ redirect_to(edit_design_path(@design))
26
+ else
27
+ render :action => "new"
28
+ end
29
+ end
30
+
31
+ def update
32
+ if @design.update_attributes(params[:design])
33
+ flash[:notice] = 'Design was successfully updated.'
34
+ redirect_to(edit_design_path(@design))
35
+ else
36
+ render :action => "edit"
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ @design.destroy
42
+ redirect_to(designs_url)
43
+ end
44
+
45
+ protected
46
+
47
+ def find_design
48
+ @design = Design.find(params[:id])
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,75 @@
1
+ module Newsletter
2
+ class ElementsController < ::Newsletter::ApplicationController
3
+ before_filter :find_element, :except => [:new,:create,:index]
4
+ before_filter :find_design
5
+ before_filter :find_fields, :except => [:new,:create,:index]
6
+ before_filter :find_field_types, :only => [:new,:create,:edit,:update]
7
+ include DeleteableActions
8
+
9
+ def index
10
+ @elements = @design.elements.
11
+ by_design(@design).paginate(:page => params[:page])
12
+ end
13
+
14
+ def new
15
+ @element = Element.new
16
+ @fields = [Field.new]
17
+ end
18
+
19
+ def edit
20
+ end
21
+
22
+ def create
23
+ @element = Element.new(params[:element])
24
+ @element.design = @design
25
+
26
+ respond_to do |format|
27
+ if @element.save
28
+ flash[:notice] = 'Element was successfully created.'
29
+ format.html { redirect_to(design_elements_path(@design)) }
30
+ format.xml { render :xml => @element, :status => :created, :location => @element }
31
+ else
32
+ format.html { render :action => "new" }
33
+ format.xml { render :xml => @element.errors, :status => :unprocessable_entity }
34
+ end
35
+ end
36
+ end
37
+
38
+ def update
39
+ respond_to do |format|
40
+ if @element.update_attributes(params[:element])
41
+ flash[:notice] = 'Element was successfully updated.'
42
+ format.html { redirect_to(design_elements_path(@design)) }
43
+ format.xml { head :ok }
44
+ else
45
+ format.html { render :action => "edit" }
46
+ format.xml { render :xml => @element.errors, :status => :unprocessable_entity }
47
+ end
48
+ end
49
+ end
50
+
51
+ def destroy
52
+ @element.destroy
53
+ redirect_to(design_elements_path(@design))
54
+ end
55
+
56
+ protected
57
+ def find_element
58
+ @element = Element.find_by_id(params[:id])
59
+ end
60
+
61
+ def find_design
62
+ return @design = @element.design if @element
63
+ @design = Design.find_by_id(params[:design_id])
64
+ end
65
+
66
+ def find_fields
67
+ return @fields = @element.fields if @element
68
+ [Field.new]
69
+ end
70
+
71
+ def find_field_types
72
+ @field_types = Field.valid_types
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,49 @@
1
+ module Newsletter
2
+ class FieldsController < ::Newsletter::ApplicationController
3
+ before_filter :find_field, :except => [:index, :new, :create]
4
+
5
+ def index
6
+ @fields = NewsletterField.find(:all)
7
+ end
8
+
9
+ def show
10
+ end
11
+
12
+ def new
13
+ @field = NewsletterField.new
14
+ end
15
+
16
+ def edit
17
+ end
18
+
19
+ def create
20
+ @field = Field.new(params[:field])
21
+ if @field.save
22
+ flash[:notice] = 'NewsletterField was successfully created.'
23
+ redirect_to(@field)
24
+ else
25
+ render :action => "new"
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @field.update_attributes(params[:field])
31
+ flash[:notice] = 'Field was successfully updated.'
32
+ redirect_to(@field)
33
+ else
34
+ render :action => "edit"
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ @field.destroy
40
+ redirect_to(fields_url)
41
+ end
42
+
43
+ protected
44
+
45
+ def find_field
46
+ @field = Field.find(params[:id])
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,104 @@
1
+ module Newsletter
2
+ class NewslettersController < ::Newsletter::ApplicationController
3
+ skip_before_filter :authorize, :only => ["archive","show"]
4
+ before_filter :find_newsletter, :only => [:editor,:publish,:unpublish,:edit,:update,:destroy,:show]
5
+ #FIXME: why do we need to place this custom code here instead of reopening the class?
6
+ skip_before_filter :authenticate, :only => [:archive,:show]
7
+
8
+
9
+ def sort
10
+ Newsletter.all.each do | newsletter |
11
+ newsletter.sequence = params["newsletters"].index(newsletter.id.to_s)+1
12
+ newsletter.save
13
+ end
14
+ head :ok
15
+ end
16
+
17
+ def archive
18
+ @newsletters = Newsletter.published
19
+ render :layout => ::Newsletter.archive_layout
20
+ end
21
+
22
+ def publish
23
+ if @newsletter.publish
24
+ flash[:notice] = 'Newsletter Published'
25
+ else
26
+ flash[:notice] = @newsletter.errors
27
+ end
28
+ redirect_to(newsletters_path)
29
+ end
30
+
31
+ def unpublish
32
+ if @newsletter.unpublish
33
+ flash[:notice] = 'Newsletter UnPublished'
34
+ else
35
+ flash[:notice] = @newsletter.errors
36
+ end
37
+ redirect_to(newsletters_path)
38
+ end
39
+
40
+ def index
41
+ @newsletters = ::Newsletter::Newsletter.active.order('created_at desc, published_at desc').paginate(:page => params[:page])
42
+ end
43
+
44
+ def show
45
+ return redirect_to(main_app.newsletter_archive_path) unless @newsletter.present?
46
+ newsletter_html = render_to_string :inline => File.readlines(@newsletter.design.view_path).join,
47
+ :locals => @newsletter.locals
48
+ if params[:mode].eql?('email')
49
+ #mailer handles substitutions
50
+ render :text => newsletter_html
51
+ else
52
+ #no substitutions
53
+ render :text => newsletter_html
54
+ end
55
+ end
56
+
57
+ def editor
58
+ params[:editor] = '1'
59
+ newsletter_html = render_to_string :inline => File.readlines(@newsletter.design.view_path).join,
60
+ :locals => @newsletter.locals
61
+ render :text => newsletter_html
62
+ end
63
+
64
+ def new
65
+ @newsletter = Newsletter.new
66
+ @designs = Design.active
67
+ end
68
+
69
+ def edit
70
+ @designs = Design.active
71
+ end
72
+
73
+ def create
74
+ @newsletter = Newsletter.new(params[:newsletter])
75
+ if @newsletter.save
76
+ flash[:notice] = 'Newsletter was successfully created.'
77
+ redirect_to(edit_newsletter_path(@newsletter))
78
+ else
79
+ @designs = Design.active
80
+ render :action => "new"
81
+ end
82
+ end
83
+
84
+ def update
85
+ if @newsletter.update_attributes(params[:newsletter])
86
+ flash[:notice] = 'Newsletter was successfully updated.'
87
+ redirect_to(edit_newsletter_path(@newsletter))
88
+ else
89
+ @designs = Design.active
90
+ render :action => "edit"
91
+ end
92
+ end
93
+
94
+ def destroy
95
+ @newsletter.destroy
96
+ redirect_to(newsletters_url)
97
+ end
98
+
99
+ protected
100
+ def find_newsletter
101
+ @newsletter = Newsletter.find_by_id(params[:id])
102
+ end
103
+ end
104
+ end