hugerte-rails 1.0.9.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 (210) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +171 -0
  4. data/Rakefile +64 -0
  5. data/app/assets/javascripts/hugerte/rails.js +51 -0
  6. data/app/assets/source/hugerte/hugerte.js +31756 -0
  7. data/app/assets/sprockets/hugerte/preinit.js.erb +4 -0
  8. data/app/assets/sprockets/hugerte.js +3 -0
  9. data/lib/hugerte/rails/asset_installer/compile.rb +44 -0
  10. data/lib/hugerte/rails/asset_installer/copy.rb +54 -0
  11. data/lib/hugerte/rails/asset_installer/copy_no_preserve.rb +14 -0
  12. data/lib/hugerte/rails/asset_installer.rb +64 -0
  13. data/lib/hugerte/rails/asset_manifest/json_manifest.rb +62 -0
  14. data/lib/hugerte/rails/asset_manifest/null_manifest.rb +12 -0
  15. data/lib/hugerte/rails/asset_manifest/propshaft_manifest.rb +43 -0
  16. data/lib/hugerte/rails/asset_manifest/yaml_manifest.rb +43 -0
  17. data/lib/hugerte/rails/asset_manifest.rb +44 -0
  18. data/lib/hugerte/rails/configuration.rb +162 -0
  19. data/lib/hugerte/rails/configuration_file.rb +50 -0
  20. data/lib/hugerte/rails/engine.rb +93 -0
  21. data/lib/hugerte/rails/environment.rb +23 -0
  22. data/lib/hugerte/rails/helper.rb +89 -0
  23. data/lib/hugerte/rails/propshaft/asset.rb +11 -0
  24. data/lib/hugerte/rails/version.rb +6 -0
  25. data/lib/hugerte/rails.rb +27 -0
  26. data/lib/hugerte-rails.rb +1 -0
  27. data/lib/tasks/hugerte-assets.rake +16 -0
  28. data/vendor/assets/config/hugerte-rails.manifest.js +3 -0
  29. data/vendor/assets/javascripts/hugerte/CHANGELOG.md +125 -0
  30. data/vendor/assets/javascripts/hugerte/README.md +21 -0
  31. data/vendor/assets/javascripts/hugerte/bower.json +27 -0
  32. data/vendor/assets/javascripts/hugerte/composer.json +52 -0
  33. data/vendor/assets/javascripts/hugerte/hugerte.d.ts +3252 -0
  34. data/vendor/assets/javascripts/hugerte/hugerte.js +339 -0
  35. data/vendor/assets/javascripts/hugerte/icons/default/icons.js +1 -0
  36. data/vendor/assets/javascripts/hugerte/icons/default/index.js +7 -0
  37. data/vendor/assets/javascripts/hugerte/license.txt +22 -0
  38. data/vendor/assets/javascripts/hugerte/models/dom/index.js +7 -0
  39. data/vendor/assets/javascripts/hugerte/models/dom/model.js +7 -0
  40. data/vendor/assets/javascripts/hugerte/package.json +32 -0
  41. data/vendor/assets/javascripts/hugerte/plugins/accordion/index.js +7 -0
  42. data/vendor/assets/javascripts/hugerte/plugins/accordion/plugin.js +7 -0
  43. data/vendor/assets/javascripts/hugerte/plugins/advlist/index.js +7 -0
  44. data/vendor/assets/javascripts/hugerte/plugins/advlist/plugin.js +7 -0
  45. data/vendor/assets/javascripts/hugerte/plugins/anchor/index.js +7 -0
  46. data/vendor/assets/javascripts/hugerte/plugins/anchor/plugin.js +7 -0
  47. data/vendor/assets/javascripts/hugerte/plugins/autolink/index.js +7 -0
  48. data/vendor/assets/javascripts/hugerte/plugins/autolink/plugin.js +7 -0
  49. data/vendor/assets/javascripts/hugerte/plugins/autoresize/index.js +7 -0
  50. data/vendor/assets/javascripts/hugerte/plugins/autoresize/plugin.js +7 -0
  51. data/vendor/assets/javascripts/hugerte/plugins/autosave/index.js +7 -0
  52. data/vendor/assets/javascripts/hugerte/plugins/autosave/plugin.js +7 -0
  53. data/vendor/assets/javascripts/hugerte/plugins/charmap/index.js +7 -0
  54. data/vendor/assets/javascripts/hugerte/plugins/charmap/plugin.js +7 -0
  55. data/vendor/assets/javascripts/hugerte/plugins/code/index.js +7 -0
  56. data/vendor/assets/javascripts/hugerte/plugins/code/plugin.js +7 -0
  57. data/vendor/assets/javascripts/hugerte/plugins/codesample/index.js +7 -0
  58. data/vendor/assets/javascripts/hugerte/plugins/codesample/plugin.js +14 -0
  59. data/vendor/assets/javascripts/hugerte/plugins/directionality/index.js +7 -0
  60. data/vendor/assets/javascripts/hugerte/plugins/directionality/plugin.js +7 -0
  61. data/vendor/assets/javascripts/hugerte/plugins/emoticons/index.js +7 -0
  62. data/vendor/assets/javascripts/hugerte/plugins/emoticons/js/emojiimages.js +3 -0
  63. data/vendor/assets/javascripts/hugerte/plugins/emoticons/js/emojis.js +2 -0
  64. data/vendor/assets/javascripts/hugerte/plugins/emoticons/plugin.js +7 -0
  65. data/vendor/assets/javascripts/hugerte/plugins/fullscreen/index.js +7 -0
  66. data/vendor/assets/javascripts/hugerte/plugins/fullscreen/plugin.js +7 -0
  67. data/vendor/assets/javascripts/hugerte/plugins/help/index.js +7 -0
  68. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ar.js +90 -0
  69. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/bg_BG.js +90 -0
  70. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ca.js +90 -0
  71. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/cs.js +90 -0
  72. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/da.js +90 -0
  73. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/de.js +90 -0
  74. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/el.js +90 -0
  75. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/en.js +90 -0
  76. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/es.js +90 -0
  77. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/eu.js +90 -0
  78. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/fa.js +90 -0
  79. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/fi.js +90 -0
  80. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/fr_FR.js +90 -0
  81. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/he_IL.js +90 -0
  82. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/hi.js +90 -0
  83. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/hr.js +90 -0
  84. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/hu_HU.js +90 -0
  85. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/id.js +90 -0
  86. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/it.js +90 -0
  87. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ja.js +90 -0
  88. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/kk.js +90 -0
  89. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ko_KR.js +90 -0
  90. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ms.js +90 -0
  91. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/nb_NO.js +90 -0
  92. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/nl.js +90 -0
  93. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/pl.js +90 -0
  94. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/pt_BR.js +90 -0
  95. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/pt_PT.js +90 -0
  96. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ro.js +90 -0
  97. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/ru.js +90 -0
  98. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/sk.js +90 -0
  99. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/sl_SI.js +90 -0
  100. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/sv_SE.js +90 -0
  101. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/th_TH.js +90 -0
  102. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/tr.js +90 -0
  103. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/uk.js +90 -0
  104. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/vi.js +90 -0
  105. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/zh_CN.js +84 -0
  106. data/vendor/assets/javascripts/hugerte/plugins/help/js/i18n/keynav/zh_TW.js +90 -0
  107. data/vendor/assets/javascripts/hugerte/plugins/help/plugin.js +7 -0
  108. data/vendor/assets/javascripts/hugerte/plugins/image/index.js +7 -0
  109. data/vendor/assets/javascripts/hugerte/plugins/image/plugin.js +7 -0
  110. data/vendor/assets/javascripts/hugerte/plugins/importcss/index.js +7 -0
  111. data/vendor/assets/javascripts/hugerte/plugins/importcss/plugin.js +7 -0
  112. data/vendor/assets/javascripts/hugerte/plugins/insertdatetime/index.js +7 -0
  113. data/vendor/assets/javascripts/hugerte/plugins/insertdatetime/plugin.js +7 -0
  114. data/vendor/assets/javascripts/hugerte/plugins/link/index.js +7 -0
  115. data/vendor/assets/javascripts/hugerte/plugins/link/plugin.js +7 -0
  116. data/vendor/assets/javascripts/hugerte/plugins/lists/index.js +7 -0
  117. data/vendor/assets/javascripts/hugerte/plugins/lists/plugin.js +7 -0
  118. data/vendor/assets/javascripts/hugerte/plugins/media/index.js +7 -0
  119. data/vendor/assets/javascripts/hugerte/plugins/media/plugin.js +7 -0
  120. data/vendor/assets/javascripts/hugerte/plugins/nonbreaking/index.js +7 -0
  121. data/vendor/assets/javascripts/hugerte/plugins/nonbreaking/plugin.js +7 -0
  122. data/vendor/assets/javascripts/hugerte/plugins/pagebreak/index.js +7 -0
  123. data/vendor/assets/javascripts/hugerte/plugins/pagebreak/plugin.js +7 -0
  124. data/vendor/assets/javascripts/hugerte/plugins/preview/index.js +7 -0
  125. data/vendor/assets/javascripts/hugerte/plugins/preview/plugin.js +7 -0
  126. data/vendor/assets/javascripts/hugerte/plugins/quickbars/index.js +7 -0
  127. data/vendor/assets/javascripts/hugerte/plugins/quickbars/plugin.js +7 -0
  128. data/vendor/assets/javascripts/hugerte/plugins/save/index.js +7 -0
  129. data/vendor/assets/javascripts/hugerte/plugins/save/plugin.js +7 -0
  130. data/vendor/assets/javascripts/hugerte/plugins/searchreplace/index.js +7 -0
  131. data/vendor/assets/javascripts/hugerte/plugins/searchreplace/plugin.js +7 -0
  132. data/vendor/assets/javascripts/hugerte/plugins/table/index.js +7 -0
  133. data/vendor/assets/javascripts/hugerte/plugins/table/plugin.js +7 -0
  134. data/vendor/assets/javascripts/hugerte/plugins/template/index.js +7 -0
  135. data/vendor/assets/javascripts/hugerte/plugins/template/plugin.js +7 -0
  136. data/vendor/assets/javascripts/hugerte/plugins/visualblocks/index.js +7 -0
  137. data/vendor/assets/javascripts/hugerte/plugins/visualblocks/plugin.js +7 -0
  138. data/vendor/assets/javascripts/hugerte/plugins/visualchars/index.js +7 -0
  139. data/vendor/assets/javascripts/hugerte/plugins/visualchars/plugin.js +7 -0
  140. data/vendor/assets/javascripts/hugerte/plugins/wordcount/index.js +7 -0
  141. data/vendor/assets/javascripts/hugerte/plugins/wordcount/plugin.js +7 -0
  142. data/vendor/assets/javascripts/hugerte/skins/content/dark/content.css +1 -0
  143. data/vendor/assets/javascripts/hugerte/skins/content/dark/content.js +2 -0
  144. data/vendor/assets/javascripts/hugerte/skins/content/dark/content.min.css +1 -0
  145. data/vendor/assets/javascripts/hugerte/skins/content/default/content.css +1 -0
  146. data/vendor/assets/javascripts/hugerte/skins/content/default/content.js +2 -0
  147. data/vendor/assets/javascripts/hugerte/skins/content/default/content.min.css +1 -0
  148. data/vendor/assets/javascripts/hugerte/skins/content/document/content.css +1 -0
  149. data/vendor/assets/javascripts/hugerte/skins/content/document/content.js +2 -0
  150. data/vendor/assets/javascripts/hugerte/skins/content/document/content.min.css +1 -0
  151. data/vendor/assets/javascripts/hugerte/skins/content/hugerte-5/content.css +1 -0
  152. data/vendor/assets/javascripts/hugerte/skins/content/hugerte-5/content.js +2 -0
  153. data/vendor/assets/javascripts/hugerte/skins/content/hugerte-5/content.min.css +1 -0
  154. data/vendor/assets/javascripts/hugerte/skins/content/hugerte-5-dark/content.css +1 -0
  155. data/vendor/assets/javascripts/hugerte/skins/content/hugerte-5-dark/content.js +2 -0
  156. data/vendor/assets/javascripts/hugerte/skins/content/hugerte-5-dark/content.min.css +1 -0
  157. data/vendor/assets/javascripts/hugerte/skins/content/writer/content.css +1 -0
  158. data/vendor/assets/javascripts/hugerte/skins/content/writer/content.js +2 -0
  159. data/vendor/assets/javascripts/hugerte/skins/content/writer/content.min.css +1 -0
  160. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/content.css +1 -0
  161. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/content.inline.css +1 -0
  162. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/content.inline.js +2 -0
  163. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/content.inline.min.css +1 -0
  164. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/content.js +2 -0
  165. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/content.min.css +1 -0
  166. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/skin.css +1 -0
  167. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/skin.js +2 -0
  168. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/skin.min.css +1 -0
  169. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/skin.shadowdom.css +1 -0
  170. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/skin.shadowdom.js +2 -0
  171. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5/skin.shadowdom.min.css +1 -0
  172. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/content.css +1 -0
  173. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/content.inline.css +1 -0
  174. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/content.inline.js +2 -0
  175. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/content.inline.min.css +1 -0
  176. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/content.js +2 -0
  177. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/content.min.css +1 -0
  178. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/skin.css +1 -0
  179. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/skin.js +2 -0
  180. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/skin.min.css +1 -0
  181. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/skin.shadowdom.css +1 -0
  182. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/skin.shadowdom.js +2 -0
  183. data/vendor/assets/javascripts/hugerte/skins/ui/hugerte-5-dark/skin.shadowdom.min.css +1 -0
  184. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/content.css +1 -0
  185. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/content.inline.css +1 -0
  186. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/content.inline.js +2 -0
  187. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/content.inline.min.css +1 -0
  188. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/content.js +2 -0
  189. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/content.min.css +1 -0
  190. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/skin.css +1 -0
  191. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/skin.js +2 -0
  192. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/skin.min.css +1 -0
  193. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/skin.shadowdom.css +1 -0
  194. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/skin.shadowdom.js +2 -0
  195. data/vendor/assets/javascripts/hugerte/skins/ui/oxide/skin.shadowdom.min.css +1 -0
  196. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/content.css +1 -0
  197. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/content.inline.css +1 -0
  198. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/content.inline.js +2 -0
  199. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/content.inline.min.css +1 -0
  200. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/content.js +2 -0
  201. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/content.min.css +1 -0
  202. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/skin.css +1 -0
  203. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/skin.js +2 -0
  204. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/skin.min.css +1 -0
  205. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/skin.shadowdom.css +1 -0
  206. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/skin.shadowdom.js +2 -0
  207. data/vendor/assets/javascripts/hugerte/skins/ui/oxide-dark/skin.shadowdom.min.css +1 -0
  208. data/vendor/assets/javascripts/hugerte/themes/silver/index.js +7 -0
  209. data/vendor/assets/javascripts/hugerte/themes/silver/theme.js +339 -0
  210. metadata +263 -0
@@ -0,0 +1,4 @@
1
+ window.hugerte = window.hugerte || {
2
+ base: '<%= HugeRTE::Rails::Engine.base %>',
3
+ suffix: ''
4
+ };
@@ -0,0 +1,3 @@
1
+ //= require hugerte/rails.js
2
+ //= require hugerte/preinit.js
3
+ //= require hugerte/hugerte.js
@@ -0,0 +1,44 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class AssetInstaller
4
+ class Compile
5
+ delegate :target, :manifest, :logger, :logical_path, :with_asset, :to => :@installer
6
+
7
+ def initialize(installer)
8
+ @installer = installer
9
+ end
10
+
11
+ def call
12
+ symlink_assets
13
+ end
14
+
15
+ private
16
+ def symlink_assets
17
+ manifest.each(/^hugerte\//) do |asset|
18
+ manifest.asset_path(asset) do |src, dest|
19
+ symlink_asset(src, dest)
20
+ end
21
+ end
22
+ end
23
+
24
+ def symlink_asset(src, dest)
25
+ with_asset(src, dest) do |src, dest|
26
+ create_symlink(src, dest)
27
+ create_symlink("#{src}.gz", "#{dest}.gz") if File.exist?("#{src}.gz")
28
+ end
29
+ end
30
+
31
+ def create_symlink(src, dest)
32
+ target = File.basename(src)
33
+
34
+ unless File.exist?(dest) && File.symlink?(dest) && File.readlink(dest) == target
35
+ logger.info "Creating symlink #{dest}"
36
+ FileUtils.ln_s(target, dest, :force => true)
37
+ else
38
+ logger.debug "Skipping symlink #{dest}, already exists"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class AssetInstaller
4
+ class Copy
5
+ delegate :assets, :target, :manifest, :logger, :logical_path, :with_asset, :to => :@installer
6
+
7
+ def initialize(installer)
8
+ @installer = installer
9
+ end
10
+
11
+ def call
12
+ cleanup_assets
13
+ copy_assets
14
+ append_to_manifest
15
+
16
+ manifest.write
17
+ end
18
+
19
+ private
20
+ def cleanup_assets
21
+ manifest.each(/^hugerte\//) do |asset|
22
+ manifest.remove_digest(asset) do |src, dest|
23
+ move_asset(src, dest)
24
+ end
25
+ end
26
+ end
27
+
28
+ def copy_assets
29
+ logger.info "Copying assets (preserving modes) to #{File.join(target, "hugerte")}"
30
+ FileUtils.cp_r(assets, target, :preserve => true)
31
+ end
32
+
33
+ def append_to_manifest
34
+ asset_files.each do |file|
35
+ manifest.append(logical_path(file), file)
36
+ end
37
+ end
38
+
39
+ def move_asset(src, dest)
40
+ with_asset(src, dest) do |src, dest|
41
+ logger.info "Removing digest from #{src}"
42
+
43
+ FileUtils.rm(dest) if File.exist?(dest)
44
+ FileUtils.mv(src, dest, :force => true)
45
+ end
46
+ end
47
+
48
+ def asset_files
49
+ Pathname.glob("#{assets}/**/*").select(&:file?)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ require_relative "copy"
2
+
3
+ module HugeRTE
4
+ module Rails
5
+ class AssetInstaller
6
+ class CopyNoPreserve < Copy
7
+ def copy_assets
8
+ logger.info "Copying assets (without preserving modes) to #{File.join(target, "hugerte")}"
9
+ FileUtils.cp_r(assets, target)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,64 @@
1
+ require_relative "asset_manifest"
2
+
3
+ require_relative "asset_installer/copy"
4
+ require_relative "asset_installer/copy_no_preserve"
5
+ require_relative "asset_installer/compile"
6
+
7
+ module HugeRTE
8
+ module Rails
9
+ class AssetInstaller
10
+ attr_reader :assets, :target, :strategy
11
+ attr_accessor :logger
12
+
13
+ def initialize(assets, target, manifest_path)
14
+ @assets = assets
15
+ @target = target
16
+ @manifest_path = manifest_path || target
17
+
18
+ @logger = Logger.new($stderr)
19
+ @logger.level = Logger::INFO
20
+ end
21
+
22
+ def install
23
+ (strategy || Copy).new(self).call
24
+ end
25
+
26
+ def log_level
27
+ @logger.level
28
+ end
29
+
30
+ def log_level=(level)
31
+ if level.is_a?(Integer)
32
+ @logger.level = level
33
+ else
34
+ @logger.level = Logger.const_get(level.to_s.upcase)
35
+ end
36
+ end
37
+
38
+ def strategy=(strategy)
39
+ if strategy.is_a?(Class)
40
+ @strategy = strategy
41
+ else
42
+ @strategy = self.class.const_get(strategy.to_s.classify)
43
+ end
44
+ end
45
+
46
+ def manifest
47
+ @manifest ||= AssetManifest.load(@manifest_path)
48
+ end
49
+
50
+ def logical_path(file)
51
+ file.relative_path_from(@assets.parent).to_s
52
+ end
53
+
54
+ def with_asset(src, dest)
55
+ if src != dest
56
+ src = File.join(@target, src)
57
+ dest = File.join(@target, dest)
58
+
59
+ yield src, dest if File.exist?(src)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,62 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class JsonManifest < AssetManifest
4
+ def self.try(manifest_path, pattern=nil)
5
+ if pattern
6
+ paths = Dir[File.join(manifest_path, pattern)]
7
+ new(paths.first) if paths.any?
8
+ elsif File.file?(manifest_path)
9
+ new(manifest_path)
10
+ end
11
+ end
12
+
13
+ def initialize(file)
14
+ @file = file
15
+ @manifest = JSON.parse(File.read(file))
16
+ end
17
+
18
+ def append(logical_path, file)
19
+ stat = File.stat(file)
20
+
21
+ assets[logical_path] = logical_path
22
+ files[logical_path] = {
23
+ "logical_path" => logical_path,
24
+ "mtime" => stat.mtime.iso8601,
25
+ "size" => stat.size,
26
+ "digest" => nil
27
+ }
28
+ end
29
+
30
+ def remove(logical_path)
31
+ if digested = assets.delete(logical_path)
32
+ files.delete(digested)
33
+ end
34
+ end
35
+
36
+ def remove_digest(logical_path)
37
+ asset_path(logical_path) do |digested, logical_path|
38
+ assets[logical_path] = logical_path
39
+ files[logical_path] = files.delete(digested).tap { |f| f["digest"] = nil }
40
+
41
+ yield digested, logical_path if block_given?
42
+ end
43
+ end
44
+
45
+ def assets
46
+ @manifest["assets"]
47
+ end
48
+
49
+ def files
50
+ @manifest["files"]
51
+ end
52
+
53
+ def dump
54
+ JSON.generate(@manifest)
55
+ end
56
+
57
+ def write
58
+ File.open(@file, "wb") { |f| f.write(dump) }
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class NullManifest < AssetManifest
4
+ def append(*); end
5
+ def remove(*); end
6
+ def remove_digest(*); end
7
+ def assets; {}; end
8
+ def each(*); end
9
+ def write; end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class PropshaftManifest < AssetManifest
4
+ def self.try(manifest_path)
5
+ json_file = File.join(manifest_path, ".manifest.json")
6
+ new(json_file) if File.exist?(json_file)
7
+ end
8
+
9
+ def initialize(file)
10
+ @file = file
11
+ @manifest = JSON.parse(File.read(file))
12
+ end
13
+
14
+ def append(logical_path, file)
15
+ assets[logical_path] = logical_path
16
+ end
17
+
18
+ def remove(logical_path)
19
+ assets.delete(logical_path)
20
+ end
21
+
22
+ def remove_digest(logical_path)
23
+ asset_path(logical_path) do |digested, logical_path|
24
+ assets[logical_path] = logical_path
25
+
26
+ yield digested, logical_path if block_given?
27
+ end
28
+ end
29
+
30
+ def assets
31
+ @manifest
32
+ end
33
+
34
+ def dump
35
+ JSON.generate(@manifest)
36
+ end
37
+
38
+ def write
39
+ File.open(@file, "wb") { |f| f.write(dump) }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class YamlManifest < AssetManifest
4
+ def self.try(manifest_path)
5
+ yaml_file = File.join(manifest_path, "manifest.yml")
6
+ new(yaml_file) if File.exist?(yaml_file)
7
+ end
8
+
9
+ def initialize(file)
10
+ @file = file
11
+ @manifest = YAML.load_file(file)
12
+ end
13
+
14
+ def append(logical_path, file)
15
+ assets[logical_path] = logical_path
16
+ end
17
+
18
+ def remove(logical_path)
19
+ assets.delete(logical_path)
20
+ end
21
+
22
+ def remove_digest(logical_path)
23
+ asset_path(logical_path) do |digested, logical_path|
24
+ assets[logical_path] = logical_path
25
+
26
+ yield digested, logical_path if block_given?
27
+ end
28
+ end
29
+
30
+ def assets
31
+ @manifest
32
+ end
33
+
34
+ def dump(io=nil)
35
+ YAML.dump(@manifest, io)
36
+ end
37
+
38
+ def write
39
+ File.open(@file, "wb") { |f| dump(f) }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ module HugeRTE
2
+ module Rails
3
+ class AssetManifest
4
+ attr_reader :file
5
+
6
+ def self.load(manifest_path)
7
+ PropshaftManifest.try(manifest_path) ||
8
+ JsonManifest.try(manifest_path, ".sprockets-manifest*.json") ||
9
+ JsonManifest.try(manifest_path, "manifest*.json") ||
10
+ JsonManifest.try(manifest_path) ||
11
+ YamlManifest.try(manifest_path) ||
12
+ NullManifest.new
13
+ end
14
+
15
+ def each(pattern)
16
+ assets.each_key do |asset|
17
+ if asset =~ pattern && !index_asset?(asset)
18
+ yield asset
19
+ end
20
+ end
21
+ end
22
+
23
+ def asset_path(logical_path)
24
+ if digested = assets[logical_path]
25
+ yield digested, logical_path if block_given?
26
+ end
27
+ end
28
+
29
+ def to_s
30
+ dump
31
+ end
32
+
33
+ protected
34
+ def index_asset?(asset)
35
+ asset =~ /\/index[^\/]*\.\w+$/
36
+ end
37
+ end
38
+
39
+ require_relative "asset_manifest/json_manifest"
40
+ require_relative "asset_manifest/null_manifest"
41
+ require_relative "asset_manifest/propshaft_manifest"
42
+ require_relative "asset_manifest/yaml_manifest"
43
+ end
44
+ end
@@ -0,0 +1,162 @@
1
+ require "active_support/hash_with_indifferent_access"
2
+
3
+ module HugeRTE::Rails
4
+ class Configuration
5
+ class Function < String
6
+ def to_javascript
7
+ self
8
+ end
9
+ end
10
+
11
+ def self.defaults
12
+ {
13
+ "selector" => "textarea.hugerte",
14
+ "cache_suffix" => "?v=#{VERSION}"
15
+ }
16
+ end
17
+
18
+ FUNCTION_REGEX = /^function\s*\(([\w\d\s_,]*)\)\s*\{([^}]*)\}|\(([\w\d\s_,]*)\)\s*=>\s*\{([^}]*)\}/
19
+ RELATIVE_PATH_REGEX = /^(\/|\.{1,2})\S*/
20
+
21
+ COMMA = ",".freeze
22
+ SPACE = " ".freeze
23
+ SEMICOLON = ";".freeze
24
+
25
+ OPTION_SEPARATORS = {
26
+ "plugins" => COMMA,
27
+ "custom_elements" => COMMA,
28
+ "entities" => COMMA,
29
+ "extended_valid_elements" => COMMA,
30
+ "font_formats" => SEMICOLON,
31
+ "fontsize_formats" => COMMA,
32
+ "invalid_elements" => COMMA,
33
+ "block_formats" => SEMICOLON,
34
+ "valid_children" => COMMA,
35
+ "valid_elements" => COMMA,
36
+ "body_id" => COMMA,
37
+ "body_class" => COMMA,
38
+ "content_css" => COMMA,
39
+ "tabfocus_elements" => COMMA,
40
+ "table_clone_elements" => SPACE,
41
+ "paste_word_valid_elements" => COMMA,
42
+ "paste_webkit_styles" => SPACE,
43
+ "paste_retain_style_properties" => SPACE,
44
+ "spellchecker_languages" => COMMA
45
+ }
46
+
47
+ OPTION_TRANSFORMERS = {
48
+ # Check for files provided in the content_css option to replace them with their actual path.
49
+ # If no corresponding stylesheet is found for a file, it will remain unchanged.
50
+ "content_css" => ->(value) {
51
+ helpers = ActionView::Base.new(ActionView::LookupContext.new([]), {}, nil)
52
+ separator = OPTION_SEPARATORS["content_css"]
53
+
54
+ value.split(separator).map { |file|
55
+ next file if RELATIVE_PATH_REGEX =~ file
56
+ helpers.stylesheet_path(file.strip) || file
57
+ }.join(separator)
58
+ }
59
+ }
60
+
61
+ attr_reader :options
62
+
63
+ def initialize(options)
64
+ @options = options
65
+ end
66
+
67
+ def self.new_with_defaults(options={})
68
+ config = new(defaults)
69
+ config = config.merge(options) if options
70
+ config
71
+ end
72
+
73
+ # Converts options into a String representing a JavaScript object
74
+ # that can be passed directly to hugerte.init
75
+ def to_javascript
76
+ options_to_javascript(options_for_hugerte)
77
+ end
78
+
79
+ # Converts options into a HugeRTE-friendly format.
80
+ #
81
+ # 1. Joins array values using OPTION_SEPARATORS
82
+ # 2. Converts JavaScript function() strings to Function objects
83
+ # 3. Applies transformations from OPTION_TRANSFORMERS
84
+ def options_for_hugerte
85
+ preprocess_options(options)
86
+ end
87
+
88
+ def merge(options)
89
+ self.class.new(self.options.merge(options))
90
+ end
91
+
92
+ private
93
+ def array_option?(key, value)
94
+ value.is_a?(Array) && OPTION_SEPARATORS[key]
95
+ end
96
+
97
+ def function_option?(value)
98
+ FUNCTION_REGEX =~ value.to_s
99
+ end
100
+
101
+ def valid_property_name?(key)
102
+ key =~ /^(?![0-9])[a-zA-Z0-9$_]+$/
103
+ end
104
+
105
+ def preprocess_options(options)
106
+ result = {}
107
+
108
+ options.each do |key, value|
109
+ key = "'#{key}'" unless valid_property_name?(key)
110
+ result[key] = preprocess_option(key, value)
111
+ end
112
+
113
+ result
114
+ end
115
+
116
+ def preprocess_option(key, value)
117
+ result = value
118
+
119
+ if result.is_a?(Hash)
120
+ result = preprocess_options(value)
121
+ elsif array_option?(key, value)
122
+ result = value.join(OPTION_SEPARATORS[key])
123
+ elsif function_option?(value)
124
+ result = Function.new(value)
125
+ end
126
+
127
+ if transformer = OPTION_TRANSFORMERS[key]
128
+ result = transformer.call(result)
129
+ end
130
+
131
+ result
132
+ end
133
+
134
+ def options_to_javascript(options, indent="")
135
+ next_indent = indent + " "
136
+
137
+ pairs = options.inject([]) do |result, (k, v)|
138
+ if v.is_a?(Hash)
139
+ v = options_to_javascript(v, next_indent)
140
+ elsif v.respond_to?(:to_javascript)
141
+ v = v.to_javascript
142
+ elsif v.respond_to?(:to_json)
143
+ v = v.to_json
144
+ end
145
+
146
+ result << [k, v].join(": ")
147
+ end
148
+
149
+ "{\n#{next_indent}#{pairs.join(",\n#{next_indent}")}\n#{indent}}"
150
+ end
151
+ end
152
+
153
+ class MultipleConfiguration < ActiveSupport::HashWithIndifferentAccess
154
+ def initialize(configurations={})
155
+ configurations = configurations.each_with_object({}) { |(name, options), h|
156
+ h[name] = Configuration.new_with_defaults(options)
157
+ }
158
+
159
+ super(configurations)
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,50 @@
1
+ module HugeRTE::Rails
2
+ class ConfigurationFile
3
+ attr_reader :path
4
+
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def configuration
10
+ @configuration = load_configuration if reload?
11
+ @configuration
12
+ end
13
+
14
+ def reload?
15
+ @configuration.nil? || (reloadable? && changed?)
16
+ end
17
+
18
+ def changed?
19
+ @last_loaded != last_updated
20
+ end
21
+
22
+ private
23
+ def reloadable?
24
+ !::Rails.application.config.cache_classes
25
+ end
26
+
27
+ def last_updated
28
+ File.exist?(path) && File.mtime(path)
29
+ end
30
+
31
+ def load_configuration
32
+ @last_loaded = last_updated
33
+
34
+ return Configuration.new_with_defaults if !File.exist?(path)
35
+
36
+ options = load_yaml(path)
37
+
38
+ if options && options.has_key?('default')
39
+ MultipleConfiguration.new(options)
40
+ else
41
+ Configuration.new_with_defaults(options)
42
+ end
43
+ end
44
+
45
+ def load_yaml(path)
46
+ result = ERB.new(IO.read(path)).result
47
+ YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(result) : YAML.load(result)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,93 @@
1
+ module HugeRTE::Rails
2
+ class Engine < ::Rails::Engine
3
+ config.hugerte = ActiveSupport::OrderedOptions.new
4
+
5
+ # Set an explicit base path for HugeRTE assets (usually defaults to /assets/hugerte)
6
+ config.hugerte.base = nil
7
+
8
+ # Set default configuration file path (defaults to config/hugerte.yml within the Rails root if unset)
9
+ config.hugerte.config_path = nil
10
+
11
+ # Set default installation method (:compile or :copy) for HugeRTE assets
12
+ # :compile - adds HugeRTE to the Sprockets load paths and creates non-digested symlinks to the digested versions
13
+ # :copy - copies across the HugeRTE assets statically
14
+ config.hugerte.install = :compile
15
+
16
+ # Set default attributes for script source tags (defaults to data-turbolinks-track="reload" for backwards compatibility)
17
+ config.hugerte.default_script_attributes = { "data-turbolinks-track" => "reload" }
18
+
19
+ initializer "precompile", :group => :all do |app|
20
+ if config.hugerte.install == :compile
21
+ app.config.assets.precompile << "hugerte-rails.manifest.js" # Sprockets 4 manifest
22
+ app.config.assets.precompile << "hugerte/*" # Sprockets 3
23
+ end
24
+
25
+ app.config.assets.precompile << "hugerte.js" << "hugerte-jquery.js"
26
+ end if defined?(Sprockets)
27
+
28
+ initializer "propshaft" do |app|
29
+ config.assets.excluded_paths << root.join("app/assets/sprockets")
30
+
31
+ if config.assets.server
32
+ # Monkey-patch Propshaft::Asset to enable access
33
+ # of HugeRTE assets without a hash digest.
34
+ require_relative "propshaft/asset"
35
+ end
36
+ end if defined?(Propshaft)
37
+
38
+ initializer "helper" do |app|
39
+ ActiveSupport.on_load(:action_view) do
40
+ include Helper
41
+ end
42
+ end
43
+
44
+ def self.base
45
+ config.hugerte.base || default_base
46
+ end
47
+
48
+ def self.default_base
49
+ File.join(asset_host || "", relative_url_root || "",
50
+ Rails.application.config.assets.prefix || "/",
51
+ "hugerte")
52
+ end
53
+
54
+ def self.relative_url_root
55
+ config = Rails.application.config
56
+
57
+ if config.respond_to?(:relative_url_root)
58
+ config.relative_url_root
59
+ else
60
+ # Fallback for Rails 3.1
61
+ config.action_controller.relative_url_root
62
+ end
63
+ end
64
+
65
+ def self.asset_host
66
+ host = Rails.application.config.action_controller.asset_host
67
+
68
+ if host.respond_to?(:call)
69
+ # Callable asset hosts cannot be supported during
70
+ # precompilation as there is no request object
71
+ nil
72
+ elsif host =~ /%d/
73
+ # Load all HugeRTE assets from the first asset host
74
+ normalize_host(host % 0)
75
+ else
76
+ normalize_host(host)
77
+ end
78
+ end
79
+
80
+ def self.normalize_host(host)
81
+ if host =~ /^https?:\/\// || host =~ /^\/\//
82
+ host
83
+ else
84
+ # Use a protocol-relative URL if not otherwise specified
85
+ "//#{host}"
86
+ end
87
+ end
88
+
89
+ def self.config_path
90
+ Rails.application.config.hugerte.config_path || ::Rails.root.join("config/hugerte.yml")
91
+ end
92
+ end
93
+ end