Beispiel #1
0
        public SassTransformerBase(string syntaxOption)
        {
            var pal = new ResourceRedirectionPlatformAdaptationLayer();
            var srs = new ScriptRuntimeSetup
            {
                HostType = typeof(SassCompilerScriptHost),
                HostArguments = new List<object> { pal },
            };
            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);
            var engine = runtime.GetRubyEngine();

            // NB: 'R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}' is a garbage path that the PAL override will
            // detect and attempt to find via an embedded Resource file
            engine.SetSearchPaths(new List<string>
                                      {
                                          @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ironruby",
                                          @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ruby\1.9.1"
                                      });

            var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("lib.sass_in_one.rb", typeof(SassCompiler)), SourceCodeKind.File);
            var scope = engine.CreateScope();
            source.Execute(scope);

            sassCompiler = scope.Engine.Runtime.Globals.GetVariable("Sass");
            option = engine.Execute(syntaxOption);
        }
        static SassFileCompiler()
        {
            _sassModule = new TrashStack<SassModule>(() => {
                var srs = new ScriptRuntimeSetup() {
                    HostType = typeof (ResourceAwareScriptHost),
                    //DebugMode = Debugger.IsAttached
                };
                srs.AddRubySetup();
                var runtime = Ruby.CreateRuntime(srs);
                var engine = runtime.GetRubyEngine();

                // NB: 'R:\' is a garbage path that the PAL override below will
                // detect and attempt to find via an embedded Resource file
                engine.SetSearchPaths(new[] {@"R:/lib/ironruby", @"R:/lib/ruby/1.9.1"});

                var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SassAndCoffee.Core.lib.sass_in_one.rb"), "R:/lib/sass_in_one.rb", SourceCodeKind.File);
                var scope = engine.CreateScope();
                source.Execute(scope);
                return new SassModule {
                    PlatformAdaptationLayer = (VirtualFilePAL)runtime.Host.PlatformAdaptationLayer,
                    Engine = scope.Engine.Runtime.Globals.GetVariable("Sass"),
                    SassOption = engine.Execute(@"{:syntax => :sass, :cache_location => ""C:/""}"),
                    ScssOption = engine.Execute(@"{:syntax => :scss, :cache_location => ""C:/""}"),
                    ExecuteRubyCode = code => engine.Execute(code, scope)
                };
            });
        }
        public MainPage()
        {
            this.InitializeComponent();

            var setup = new ScriptRuntimeSetup();
            setup.HostType = typeof(DlrHost);
            setup.AddRubySetup();

            var runtime = Ruby.CreateRuntime(setup);
            this.engine = Ruby.GetEngine(runtime);
            this.scope = engine.CreateScope();
            this.scope.SetVariable("Main", this);

            runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);

            string outputText = @"
box = main.find_name('OutputBox')
p box.text_alignment
box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
p box.text_alignment
";
            InputBox.IsSpellCheckEnabled = false;
            OutputBox.IsSpellCheckEnabled = false;
            InputBox.Document.SetText(TextSetOptions.None, outputText);
        }
Beispiel #4
0
        public MainPage()
        {
            this.InitializeComponent();

            var setup = new ScriptRuntimeSetup();
            setup.HostType = typeof(DlrHost);
            setup.AddRubySetup();

            var runtime = Ruby.CreateRuntime(setup);
            this.engine = Ruby.GetEngine(runtime);
            this.scope = engine.CreateScope();
            this.scope.SetVariable("Main", this);

            runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);

            string outputText = @"
            box = main.find_name('OutputBox')
            p box.text_alignment
            box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
            p box.text_alignment
            ";
            InputBox.IsSpellCheckEnabled = false;
            OutputBox.IsSpellCheckEnabled = false;
            InputBox.Document.SetText(TextSetOptions.None, outputText);

            // http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx

            IInspectable insp = (IInspectable)InputBox.Document;
            string winTypeName;
            insp.GetRuntimeClassName(out winTypeName);
            Guid[] iids;
            int iidCount;
            insp.GetIids(out iidCount, out iids);

               // winTypeName = "Windows.Foundation.Collections.IIterator`1<Windows.Foundation.Collections.IMapView`2<Windows.Foundation.Collections.IVector`1<String>, String>>";

            var parts = ParseWindowsTypeName(winTypeName);
            Type type = MakeWindowsType(parts);
            var guid = type.GetTypeInfo().GUID;
        }
Beispiel #5
0
        public DlrHost()
        {
            this._Runtime = new Lazy<ScriptRuntime>(() => {
                var setup = new ScriptRuntimeSetup();
                setup.DebugMode = true;

                setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
                setup.AddRubySetup();

                var runtime = new ScriptRuntime(setup);
                AppDomain.CurrentDomain.GetAssemblies().ForEach(assm => runtime.LoadAssembly(assm));
                return runtime;
            });

            this._Scope = new Lazy<ScriptScope>(() => {
                var scope = this._Runtime.Value.CreateScope();
                return scope;
            });

            this._Extensions = new Lazy<ISet<string>>(() => {
                return new HashSet<string>(this._Runtime.Value.Setup.LanguageSetups.SelectMany(lang => lang.FileExtensions), StringComparer.OrdinalIgnoreCase);
            });
        }
Beispiel #6
0
        void Initialize()
        {
            if (initialized) return;

            pal = new CassettePlatformAdaptationLayer(new ResourceRedirectionPlatformAdaptationLayer(), RootDirectory);
            var srs = new ScriptRuntimeSetup
            {
                HostType = typeof(SassCompilerScriptHost),
                HostArguments = new List<object> { pal },
            };
            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);
            engine = runtime.GetRubyEngine();

            // NB: 'R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}' is a garbage path that the PAL override will
            // detect and attempt to find via an embedded Resource file
            engine.SetSearchPaths(new List<string>
            {
                @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ironruby",
                @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ruby\1.9.1"
            });

            var source = engine.CreateScriptSourceFromString(
                Utility.ResourceAsString("lib.sass_in_one.rb", typeof(SassAndCoffee.Ruby.Sass.SassCompiler)),
                SourceCodeKind.File);
            scope = engine.CreateScope();
            source.Execute(scope);

            sassCompiler = scope.Engine.Runtime.Globals.GetVariable("Sass");
            sassOption = engine.Execute("{:cache => false, :syntax => :sass}");
            scssOption = engine.Execute("{:cache => false, :syntax => :scss}");

            initialized = true;
        }
Beispiel #7
0
        public void RubyHosting5() {
            // app-domain creation:
            if (_driver.PartialTrust) return;

            AppDomain domain = AppDomain.CreateDomain("foo");

            var rs = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup ls = rs.GetRubySetup();
            Debug.Assert(ls.Names.IndexOf("IronRuby") != -1);

            var newSetup = new ScriptRuntimeSetup();
            newSetup.AddRubySetup((s) => {
                s.Options["Compatibility"] = RubyCompatibility.Ruby19;
                s.Options["LibraryPaths"] = ls.Options["LibraryPaths"];
            });

            ScriptRuntime runtime = ScriptRuntime.CreateRemote(domain, newSetup);
            ScriptEngine engine = runtime.GetRubyEngine();
            Assert(engine.RequireFile("fcntl") == true);
            Assert(engine.Execute<bool>("Object.constants.include?(:Fcntl)") == true);
        }
Beispiel #8
0
        public string CompileSass(string input, SassMode mode)
        {
            var srs = new ScriptRuntimeSetup() { HostType = typeof(ResourceAwareScriptHost) };
            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);

            var engine = runtime.GetRubyEngine();

            engine.SetSearchPaths(new List<string> { @"R:\lib\ironruby", @"R:\lib\ruby\1.9.1" });

            var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SquishIt.Sass.lib.sass_in_one.rb"), SourceCodeKind.File);
            var scope = engine.CreateScope();
            source.Execute(scope);

            dynamic sassMode = mode == SassMode.Sass
                                   ? engine.Execute("{:syntax => :sass}")
                                   : engine.Execute("{:syntax => :scss}");

            var sassEngine = scope.Engine.Runtime.Globals.GetVariable("Sass");

            return (string) sassEngine.compile(input, sassMode);
        }
        public void Init(HttpApplication context)
        {
            var srs = new ScriptRuntimeSetup() {HostType = typeof (ResourceAwareScriptHost)};
            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);
            var engine = runtime.GetRubyEngine();
            engine.SetSearchPaths(new List<string>() {@"R:\lib\ironruby", @"R:\lib\ruby\1.9.1"});

            var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SassAndCoffee.lib.sass_in_one.rb"), SourceCodeKind.File);
            var scope = engine.CreateScope();
            source.Execute(scope);

            _scssOption = engine.Execute("{:syntax => :scss}");
            _sassOption = engine.Execute("{:syntax => :sass}");
            _sassModule = scope.Engine.Runtime.Globals.GetVariable("Sass");
        }
        static SassFileCompiler()
        {
            _sassModule = new TrashStack<SassModule>(() => {
                var srs = new ScriptRuntimeSetup() {HostType = typeof (ResourceAwareScriptHost)};
                srs.AddRubySetup();
                var runtime = Ruby.CreateRuntime(srs);
                var engine = runtime.GetRubyEngine();
                engine.SetSearchPaths(new List<string>() {@"R:\lib\ironruby", @"R:\lib\ruby\1.9.1"});

                var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SassAndCoffee.lib.sass_in_one.rb"), SourceCodeKind.File);
                var scope = engine.CreateScope();
                source.Execute(scope);

                return new SassModule() {
                    Engine = scope.Engine.Runtime.Globals.GetVariable("Sass"),
                    SassOption = engine.Execute("{:syntax => :sass}"),
                    ScssOption = engine.Execute("{:syntax => :scss}"),
                    ExecuteRubyCode = code => engine.Execute(code, scope),
                };
            });
        }
Beispiel #11
0
 /*!*/
 protected override ScriptRuntime CreateRuntime()
 {
     var setup = new ScriptRuntimeSetup();
     setup.AddRubySetup();
     return _factory.CreateRuntime(setup);
 }
Beispiel #12
0
 /*!*/
 protected virtual ScriptRuntime CreateRuntime()
 {
     ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
     setup.AddRubySetup();
     setup.DebugMode = true;
     return Ruby.CreateRuntime(setup);
 }